Skip to content

Commit

Permalink
fix(Future Select): Remove role=dialog from listbox container (#4968)
Browse files Browse the repository at this point in the history
* fix(Future Select): Remove role=dialog from listbox container

* Update tests

* Update test assertion to match other one

* Adjust 1 and delete 1 test to be more user focused
  • Loading branch information
dougmacknz authored Aug 26, 2024
1 parent 6665db9 commit 0d5efc2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-trees-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@kaizen/components": patch
---

Remove role=dialog from Select listbox container
3 changes: 3 additions & 0 deletions packages/components/src/MultiSelect/MultiSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export const MultiSelect = ({
<Popover
refs={refs}
id={`${id}--popover`}
role="dialog"
aria-modal="true"
tabIndex={-1}
focusOnProps={{
enabled: true,
onClickOutside,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ export const Popover = <RT extends ReferenceType>({
ref={refs.setFloating}
style={floatingStyles}
className={classnames(styles.popover, classNameOverride)}
role="dialog"
aria-modal="true"
tabIndex={-1}
{...restProps}
>
{children}
Expand Down
24 changes: 5 additions & 19 deletions packages/components/src/__future__/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,6 @@ describe("<Select />", () => {
})
})

it("will portal to the document body by default", async () => {
render(<SelectWrapper selectedKey="batch-brew" isOpen />)

const popover = screen.getByRole("dialog")
// expected div that FocusOn adds to the popover
const popoverFocusWrapper = popover.parentNode

await waitFor(() => {
const expectedBodyTag = popoverFocusWrapper?.parentNode
expect(expectedBodyTag?.nodeName).toEqual("BODY")
})
})

it("will render as a descendant of the element matching the id", async () => {
const SelectWithPortal = (): JSX.Element => {
const portalContainerId = "id--portal-container"
Expand All @@ -401,13 +388,13 @@ describe("<Select />", () => {

await waitFor(() => {
const newPortalRegion = screen.getByTestId("id--portal-container-test")
const popover = within(newPortalRegion).getByRole("dialog")
const listbox = within(newPortalRegion).getByRole("listbox")

expect(popover).toBeInTheDocument()
expect(listbox).toBeInTheDocument()
})
})

it("will portal to the document body if the id does not match", async () => {
it("will still render the listbox when the portal id given is invalid", async () => {
const SelectWithPortal = (): JSX.Element => {
const expectedContainerId = "id--portal-container"
return (
Expand All @@ -424,9 +411,8 @@ describe("<Select />", () => {
render(<SelectWithPortal />)

await waitFor(() => {
const popover = within(document.body).getByRole("dialog")

expect(popover).toBeInTheDocument()
const listbox = within(document.body).getByRole("listbox")
expect(listbox).toBeInTheDocument()
})
})
})
Expand Down

0 comments on commit 0d5efc2

Please sign in to comment.