Skip to content

Commit 8cb85a6

Browse files
authored
followup for #3636 (#3895)
* followup for #3636
1 parent 2973063 commit 8cb85a6

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

lib/phoenix_component.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,9 +3154,9 @@ defmodule Phoenix.Component do
31543154
def focus_wrap(assigns) do
31553155
~H"""
31563156
<div id={@id} phx-hook="Phoenix.FocusWrap" {@rest}>
3157-
<span id={"#{@id}-start"} tabindex="0" aria-hidden="true"></span>
3157+
<div id={"#{@id}-start"} tabindex="0" aria-hidden="true"></div>
31583158
{render_slot(@inner_block)}
3159-
<span id={"#{@id}-end"} tabindex="0" aria-hidden="true"></span>
3159+
<div id={"#{@id}-end"} tabindex="0" aria-hidden="true"></div>
31603160
</div>
31613161
"""
31623162
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
defmodule Phoenix.LiveViewTest.E2E.Issue3636Live do
2+
# https://github.com/phoenixframework/phoenix_live_view/issues/3636
3+
use Phoenix.LiveView
4+
5+
@impl Phoenix.LiveView
6+
def mount(_params, _session, socket) do
7+
{:ok, socket}
8+
end
9+
10+
@impl Phoenix.LiveView
11+
def render(assigns) do
12+
~H"""
13+
<style>
14+
.space-x-8 > :not([hidden]) ~ :not([hidden]) {
15+
margin-left: 2rem;
16+
}
17+
</style>
18+
19+
<div class="container mx-auto p-8">
20+
<button>Outside 1</button>
21+
<.focus_wrap id="focus-wrap" class="space-x-8">
22+
<button id="first" class="border rounded py-2 px-4">One</button>
23+
<button id="second" class="border rounded py-2 px-4">Two</button>
24+
<button id="third" class="border rounded py-2 px-4">Three</button>
25+
</.focus_wrap>
26+
<button>Outside 2</button>
27+
</div>
28+
"""
29+
end
30+
end

test/e2e/test_helper.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ defmodule Phoenix.LiveViewTest.E2E.Router do
184184
live "/3529", Issue3529Live
185185
live "/3612/a", Issue3612.ALive
186186
live "/3612/b", Issue3612.BLive
187+
live "/3636", Issue3636Live
187188
live "/3651", Issue3651Live
188189
live "/3656", Issue3656Live
189190
live "/3658", Issue3658Live

test/e2e/tests/issues/3636.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test, expect } from "../../test-fixtures";
2+
import { syncLV } from "../../utils";
3+
4+
// https://github.com/phoenixframework/phoenix_live_view/issues/3636
5+
test("focus_wrap - focuses first element when entering focus from outside", async ({
6+
page,
7+
browserName,
8+
}) => {
9+
// skip if webkit, since it doesn't have tab focus enabled by default
10+
if (browserName === "webkit") {
11+
test.skip();
12+
}
13+
await page.goto("/issues/3636");
14+
await syncLV(page);
15+
// put focus next to the third button
16+
await page.mouse.click(250, 37.5);
17+
await page.keyboard.press("Tab");
18+
await expect(page.getByRole("button", { name: "One" })).toBeFocused();
19+
});

test/phoenix_component/components_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ defmodule Phoenix.LiveView.ComponentsTest do
144144
assert t2h(template) ==
145145
~X"""
146146
<div id="wrap" phx-hook="Phoenix.FocusWrap" class="foo">
147-
<span id="wrap-start" tabindex="0" aria-hidden="true"></span>
147+
<div id="wrap-start" tabindex="0" aria-hidden="true"></div>
148148
<div>content</div>
149-
<span id="wrap-end" tabindex="0" aria-hidden="true"></span>
149+
<div id="wrap-end" tabindex="0" aria-hidden="true"></div>
150150
</div>
151151
"""
152152
end

0 commit comments

Comments
 (0)