Skip to content

Commit

Permalink
Apply request changes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbrasileiro committed Sep 20, 2021
1 parent a570d36 commit b00490c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
27 changes: 20 additions & 7 deletions packages/store-ui/src/molecules/Modal/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ describe('Modal', () => {

expect(document.querySelector(`[data-testid="${modalTestId}"]`)).toBeNull()

const modalTriggerButton = getByTestId('trigger')

fireEvent.click(modalTriggerButton)
fireEvent.click(getByTestId('trigger'))

expect(getByTestId('store-modal')).toBeInTheDocument()
})
})

describe('Modal WAI-ARIA Specifications', () => {
// WAI-ARIA tests
// https://www.w3.org/TR/wai-aria-practices-1.1/#dialog_modal
it('Test WAI-ARIA Specifications: Focus first element', () => {
it('Focus first element', () => {
const { getByTestId } = render(<TestModal />)

// Open the modal
Expand All @@ -66,7 +66,7 @@ describe('Modal', () => {
expect(getByTestId('first-input')).toHaveFocus()
})

it('Test WAI-ARIA Specifications: Loop focus', () => {
it('Loop focus', () => {
const { getByTestId } = render(<TestModal />)

// Open the modal
Expand All @@ -92,7 +92,7 @@ describe('Modal', () => {
expect(getByTestId('first-input')).toHaveFocus()
})

it('Test WAI-ARIA Specifications: Focus last element before the modal was opened', () => {
it('Focus last element before the modal was opened', () => {
const { getByTestId } = render(<TestModal />)
const triggerModalButton = getByTestId('trigger')

Expand All @@ -112,7 +112,7 @@ describe('Modal', () => {
expect(triggerModalButton).toHaveFocus()
})

it('Test WAI-ARIA Specifications: Close when press escape', () => {
it('Close when press escape', () => {
const { getByTestId } = render(<TestModal />)

fireEvent.click(getByTestId('trigger'))
Expand All @@ -128,4 +128,17 @@ describe('Modal', () => {

expect(document.querySelector(`[data-testid="${modalTestId}"]`)).toBeNull()
})

it('Close when click outside the modal', () => {
const { getByTestId } = render(<TestModal />)

fireEvent.click(getByTestId('trigger'))

expect(getByTestId('store-modal')).toBeInTheDocument()

// Close the modal
fireEvent.click(getByTestId('store-overlay'))

expect(document.querySelector(`[data-testid="${modalTestId}"]`)).toBeNull()
})
})
6 changes: 1 addition & 5 deletions packages/store-ui/src/molecules/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,9 @@ export interface ModalProps extends ModalContentProps {
* the dialog.
*/
onDismiss?: (event: MouseEvent | KeyboardEvent) => void
/**
* Defines a string value that labels the current element.
* @see aria-labelledby.
*/
'aria-label'?: AriaAttributes['aria-label']
/**
* Identifies the element (or elements) that labels the current element.
* @see aria-labelledby https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby
*/
'aria-labelledby'?: AriaAttributes['aria-label']
}
Expand Down
2 changes: 1 addition & 1 deletion packages/store-ui/src/molecules/Modal/useTrapFocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const useTrapFocus = ({
document.hasFocus() ? (document.activeElement as HTMLElement) : null
)

// Focus back on the element that was focused before the trapFocusNode
// Focus back on the element that was focused when useTrapFocus is triggered.
useEffect(() => {
const nodeToRestore = nodeToRestoreRef.current

Expand Down

0 comments on commit b00490c

Please sign in to comment.