Skip to content

Commit

Permalink
fix: avoid Modal (dialog) from being omitted in accessibility tree
Browse files Browse the repository at this point in the history
This omits the modal root from getting
aria-hidden="true" added to it, which
removes the modal from the accessibility tree
  • Loading branch information
thebreiflabb authored and tujoworker committed Feb 8, 2022
1 parent b91e745 commit 7ce12fc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/dnb-eufemia/src/components/modal/ModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default class ModalContent extends React.PureComponent<
[
// Bypass modal content
'.dnb-modal__content *',
`#dnb-modal-${this.props.root_id || 'root'}`,
`#dnb-modal-${this.props.root_id || 'root'} *`,

// TODO: Eventually in future, make it possible to bypass invalidation from outside
Expand Down
31 changes: 31 additions & 0 deletions packages/dnb-eufemia/src/components/modal/__tests__/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,37 @@ describe('Modal component', () => {
Comp.find('button.dnb-modal__close-button').simulate('click')
})

it('should not add aria-hidden to the dialog root', () => {
const modalContent = 'Modal Content'

const Comp = mount(
<div>
<Component
{...props}
title={null}
modal_content={null}
direct_dom_return={false}
>
{modalContent}
</Component>

<button id="my-button">I should become hidden after open</button>
</div>,
{ attachTo: attachToBody() }
)

Comp.find('button.dnb-modal__trigger').simulate('click')

const id = `#dnb-modal-${props.id}`
const modalRoot = document.querySelector(id)
const outsideButton = document.querySelector('#my-button')

expect(modalRoot.getAttribute('aria-hidden')).toBeFalsy()
expect(outsideButton.getAttribute('aria-hidden')).toEqual('true')

Comp.find('button.dnb-modal__close-button').simulate('click')
})

it('runs expected side effects on desktop', () => {
const Comp = mount(<Component {...props} />)
const elem = Comp.find('button')
Expand Down

0 comments on commit 7ce12fc

Please sign in to comment.