Skip to content

Commit

Permalink
Enhance and generalise a11y advice
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed May 25, 2023
1 parent 4ce5d35 commit dc495bc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
10 changes: 2 additions & 8 deletions packages/dnb-eufemia/src/components/modal/ModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,8 @@ export default class ModalContent extends React.PureComponent<
focusElement.focus()

const noH1Elem = elem.querySelector('h1, h2, h3')
if (
typeof noH1Elem?.tagName !== 'undefined' &&
noH1Elem?.tagName !== 'H1'
) {
warn(
'You have to provide a h1 element at first – instead of:',
noH1Elem
)
if (noH1Elem?.tagName !== 'H1') {
warn('A Dialog or Drawer needs a h1 as its first element!')
}
} catch (e) {
warn(e)
Expand Down
16 changes: 6 additions & 10 deletions packages/dnb-eufemia/src/components/modal/__tests__/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
attachToBody, // in order to use document.activeElement properly
loadScss,
} from '../../../core/jest/jestSetup'
import { fireEvent, render } from '@testing-library/react'
import { fireEvent, render, waitFor } from '@testing-library/react'
import Input from '../../input/Input'
import Component, { OriginalComponent } from '../Modal'
import Button from '../../button/Button'
Expand Down Expand Up @@ -363,26 +363,22 @@ describe('Modal component', () => {
const log = global.console.log
global.console.log = jest.fn()

const H2 = <h2>h2</h2>
const H2 = <h2 className="custom-h2">h2</h2>

const Comp = mount(
render(
<Component no_animation={true}>
<DialogContent>
<Component.Header>{H2}</Component.Header>
</DialogContent>
</Component>,
{ attachTo: attachToBody() }
</Component>
)

// open
Comp.find('button').simulate('click')

await wait(1)
await waitFor(() => fireEvent.click(document.querySelector('button')))

expect(helpers.warn).toHaveBeenCalledTimes(1)
expect(helpers.warn).toHaveBeenCalledWith(
'You have to provide a h1 element at first – instead of:',
expect.anything()
'A Dialog or Drawer needs a h1 as its first element!'
)

global.console.log = log
Expand Down

0 comments on commit dc495bc

Please sign in to comment.