Skip to content

Commit

Permalink
feat: update modal accessibility improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Chisomchima committed Feb 21, 2024
1 parent b30c1b1 commit 664e080
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
4 changes: 2 additions & 2 deletions collections/forms/i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-02-21T10:19:12.883Z\n"
"PO-Revision-Date: 2024-02-21T10:19:12.883Z\n"
"POT-Creation-Date: 2024-02-21T15:08:47.300Z\n"
"PO-Revision-Date: 2024-02-21T15:08:47.300Z\n"

msgid "Upload file"
msgstr "Upload file"
Expand Down
25 changes: 16 additions & 9 deletions components/modal/src/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Layer } from '@dhis2-ui/layer'
import { spacers, spacersNum, sharedPropTypes } from '@dhis2/ui-constants'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useEffect } from 'react'
import React, { useCallback, useEffect } from 'react'
import { resolve } from 'styled-jsx/css'
import { CloseButton } from './close-button.js'

Expand All @@ -29,19 +29,26 @@ export const Modal = ({
}) => {
const layerStyles = resolveLayerStyles(hide)

const handleKeyDown = (event) => {
if (event.key === 'Escape' && onClose) {
onClose()
}
}
const handleKeyDown = useCallback(
(event) => {
if (event.key === 'Escape' && onClose) {
onClose()
}
},
[onClose]
)

useEffect(() => {
document.addEventListener('keydown', handleKeyDown)
if (hide) {
return
}
const handleKeyDownCallback = handleKeyDown
document.addEventListener('keydown', handleKeyDownCallback)

return () => {
document.removeEventListener('keydown', handleKeyDown)
document.removeEventListener('keydown', handleKeyDownCallback)
}
}, [onClose])
}, [handleKeyDown, hide])

return (
<Layer
Expand Down

0 comments on commit 664e080

Please sign in to comment.