Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Future Select): remove redundant focus management #5015

Merged
merged 5 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/twelve-pugs-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@kaizen/components": patch
---

Future Select: remove redundant focus management

Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ describe("<FilterSelect>", () => {
render(<FilterSelectWrapper isOpen />)
expect(screen.queryByRole("listbox")).toBeVisible()
await waitFor(() => {
expect(
screen.queryByRole("option", { name: "Regular" })
).toHaveFocus()
expect(screen.queryByRole("listbox")).toHaveFocus()
})
})

Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/__future__/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ describe("<Select />", () => {
})

describe("Given the menu is opened", () => {
it("moves the focus to the first focusable element inside the menu initially", async () => {
it("focuses the listbox initially", async () => {
const { getByRole } = render(<SelectWrapper defaultOpen />)
expect(getByRole("listbox")).toBeVisible()
await waitFor(() => {
expect(getByRole("option", { name: "Short black" })).toHaveFocus()
expect(getByRole("listbox")).toHaveFocus()
})
})
it("is closed when hits the escape key", async () => {
Expand Down Expand Up @@ -305,12 +305,12 @@ describe("<Select />", () => {
})
})

it("keeps the focus ring at the first element when hits arrow up key on it", async () => {
it("focuses the last item in the list on up arrow press", async () => {
const { getByRole } = render(<SelectWrapper />)
await user.tab()
await user.keyboard("{ArrowUp}")
await waitFor(() => {
expect(getByRole("option", { name: "Short black" })).toHaveFocus()
expect(getByRole("option", { name: "Magic" })).toHaveFocus()
})
})

Expand Down
11 changes: 1 addition & 10 deletions packages/components/src/__future__/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,7 @@ export const Select = <Option extends SelectOption = SelectOption>({
trigger(selectToggleProps, selectToggleProps.ref)
)}
{state.isOpen && (
<Popover
id={popoverId}
portalContainer={portalContainer}
refs={refs}
focusOnProps={{
onEscapeKey: state.close,
onClickOutside: state.close,
noIsolation: true,
}}
>
<Popover id={popoverId} portalContainer={portalContainer} refs={refs}>
<SelectProvider<Option> state={state}>
<SelectPopoverContents menuProps={menuProps}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
padding: 0;
display: grid;
max-height: 22rem;
}

&.focus {
outline: none;
}
.listBox:focus-visible {
outline: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ListBox = <Option extends SelectOption>({
const { state } = useSelectContext<Option>()
const ref = React.useRef<HTMLUListElement>(null)
const { listBoxProps } = useListBox(
{ ...menuProps, disallowEmptySelection: true, autoFocus: "first" },
{ ...menuProps, disallowEmptySelection: true },
state,
ref
)
Expand Down