Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update modal accessibility improvements #1457

Closed
wants to merge 9 commits into from

Conversation

Chisomchima
Copy link
Member

@Chisomchima Chisomchima commented Feb 20, 2024

Implements Jira Ticket


Description

Implements Jira Ticket by updating the Modal CloseButton component to update title and aria-label attributes, as well as the close onClick of the escape button


Known issues

  • None

Checklist

  • API docs are generated
  • Tests were added
  • Storybook demos were added

All points above should be relevant for feature PRs. For bugfixes, some points might not be relevant. In that case, just check them anyway to signal the work is done.


Screenshots

  • None

supporting text

@Chisomchima Chisomchima requested a review from a team as a code owner February 20, 2024 13:01
@Chisomchima Chisomchima marked this pull request as draft February 20, 2024 13:01
@dhis2-bot
Copy link
Contributor

dhis2-bot commented Feb 20, 2024

🚀 Deployed on https://pr-1457--dhis2-ui.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify February 20, 2024 13:05 Inactive
Copy link

cypress bot commented Feb 20, 2024

334 failed tests on run #3297 ↗︎

334 250 0 0 Flakiness 0

Details:

Merge branches 'LIBS-567/modal-accessibility' and 'LIBS-567/modal-accessibility'...
Project: ui Commit: ec9299d760
Status: Failed Duration: 09:58 💡
Started: Mar 19, 2024 4:02 PM Ended: Mar 19, 2024 4:12 PM
Failed  components/header-bar/src/features/the_search_should_escape_regexp_character.feature • 30 failed tests • e2e

View Output

Test Artifacts
The search should escape regexp characters > The user searches for an app with a regex character (example #1) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #2) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #3) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #4) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #5) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #6) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #7) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #8) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #9) Screenshots
The search should escape regexp characters > The user searches for an app with a regex character (example #10) Screenshots
The first 10 failed tests are shown, see all 30 tests in Cypress Cloud.
Failed  components/header-bar/src/features/the_headerbar_contains_a_profile_menu.feature • 11 failed tests • e2e

View Output

Test Artifacts
The HeaderBar contains a profile menu > The HeaderBar shows a text icon if the user does not have an avatar Screenshots
The HeaderBar contains a profile menu > The HeaderBar shows an image icon if the user has an avatar Screenshots
The HeaderBar contains a profile menu > The menu opens Screenshots
The HeaderBar contains a profile menu > The user name and email are displayed Screenshots
The HeaderBar contains a profile menu > The user can edit his profile Screenshots
The HeaderBar contains a profile menu > The user can go to the settings Screenshots
The HeaderBar contains a profile menu > The user can go to his account Screenshots
The HeaderBar contains a profile menu > The user can go to the help page Screenshots
The HeaderBar contains a profile menu > The user can go to the About DHIS2 page Screenshots
The HeaderBar contains a profile menu > The user can log out Screenshots
The first 10 failed tests are shown, see all 11 tests in Cypress Cloud.
Failed  components/alert/src/alert-bar/features/api.feature • 5 failed tests • e2e

View Output

Test Artifacts
AlertBar API > AlertBar icon shows by default Screenshots
AlertBar API > Custom AlertBar icon Screenshots
AlertBar API > Standard AlertBar with a message Screenshots
AlertBar API > The AlertBar renders with a permanent flag Screenshots
AlertBar API > AlertBar will call the onHidden cb when hidden Screenshots
Failed  components/calendar/src/features/supports_nepali_calendar.feature • 4 failed tests • e2e

View Output

Test Artifacts
The Calendar renders in Nepali calendar system > Display a Nepali calendar in Nepali Screenshots
The Calendar renders in Nepali calendar system > Select a day in the Nepali calendar in Nepali Screenshots
The Calendar renders in Nepali calendar system > Display a Nepali calendar in English Screenshots
The Calendar renders in Nepali calendar system > Select a day in the Nepali calendar in English Screenshots
Failed  components/header-bar/src/features/the_headerbar_should_display_debug_version_infos.feature • 8 failed tests • e2e

View Output

Test Artifacts
The HeaderBar should display debug version infos > The debug version infos are displayed in the profile menu Screenshots
The HeaderBar should display debug version infos > The debug version info modal is displayed when clicking on the menu item Screenshots
The HeaderBar should display debug version infos > The debug version info modal displays debug info Screenshots
The HeaderBar should display debug version infos > The debug version info should be copied to clipboard Screenshots
The HeaderBar should display debug version infos > The debug version infos are displayed with unknown dhis2 version in the profile menu Screenshots
The HeaderBar should display debug version infos > The debug version infos are displayed with unknown app name and version in the profile menu Screenshots
The HeaderBar should display debug version infos > The debug version infos are displayed with unknown app name in the profile menu Screenshots
The HeaderBar should display debug version infos > The debug version infos are displayed with unknown app version in the profile menu Screenshots

The first 5 failed specs are shown, see all 149 specs in Cypress Cloud.

Review all test suite changes for PR #1457 ↗︎

}
}

document.addEventListener('keydown', handleKeyDown)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better for this is to have it as a useEffect that subscribes to the event and cleans itself when the component is unmounted. Otherwise we will have an event listener registered forever even after the modal is closed.

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

useEffect(() => {
    
    document.addEventListener('keydown', handleKeyDown)

    return cleanup = () => {
       document.removeEventListener('keydown', handleKeyDown)
    }
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I have updated this commit with the changes above.

data-test="dhis2-modal-close-button"
onClick={createClickHandler(onClick)}
aria-label="Close modal dialog"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the labels, please use i18n.t('Close modal dialog') - like that, the label will be translated and the correct message in the appropriate language used (not hardcoded to english)

@kabaros kabaros requested a review from cooper-joe February 20, 2024 16:16
@kabaros kabaros marked this pull request as ready for review February 20, 2024 16:16
@dhis2-bot dhis2-bot temporarily deployed to netlify February 21, 2024 11:02 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify February 21, 2024 11:08 Inactive
components/modal/src/modal/modal.js Outdated Show resolved Hide resolved
components/modal/src/modal/modal.js Outdated Show resolved Hide resolved
@dhis2-bot dhis2-bot temporarily deployed to netlify February 21, 2024 15:17 Inactive
import { Modal } from './modal.js'

describe('Modal', () => {
describe('Accessibility', () => {
it('closes when ESC key is pressed', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the Split Button-PR I think it would make sense to add some test-cases with button component that also handle "ESC keys". Eg. Selects. And test that the modal is not closed if esc is pressed when that is open.

@dhis2-bot dhis2-bot temporarily deployed to netlify February 27, 2024 09:46 Inactive
}

const handleKeyDown = (event) => {
event.preventDefault()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if preventDefault is necessary, I believe it's just for some HTML-components. Maybe @ismay has some input in regards to this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without the prevent default, keys like enter and space bar work as well, what I want is for escape key only to be able to close the modal.

Copy link
Member

@Birkbjo Birkbjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Just one question I'm not totally sure of in regards to preventDefault().

Would be great to have some tests for the modal that tests for correct escape-handling with other components like Select and SplitButton inside the modal. But we can add that later, and after the SplitButton PR is merged.

@kabaros kabaros changed the base branch from master to alpha March 18, 2024 15:43
feat: update modal accessibility improvements
@kabaros kabaros force-pushed the LIBS-567/modal-accessibility branch from 21c8086 to 9e7abc3 Compare March 18, 2024 16:24
@dhis2-bot dhis2-bot temporarily deployed to netlify March 18, 2024 16:39 Inactive
@Chisomchima Chisomchima changed the title feat: update modal accessibility improvements chore: update modal accessibility improvements Mar 19, 2024
feat: update modal accessibility improvements
@dhis2-bot dhis2-bot temporarily deployed to netlify March 19, 2024 10:22 Inactive

const createClickHandler = (onClick) => (event) => {
onClick({}, event)
}

export const CloseButton = ({ onClick }) => (
<button
title="Close modal dialog"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Chisomchima the title is still not translated

@Chisomchima Chisomchima force-pushed the LIBS-567/modal-accessibility branch from 6855a96 to 89edb8b Compare March 19, 2024 15:28
…essibility' of github.com:dhis2/ui into LIBS-567/modal-accessibility
@Chisomchima Chisomchima reopened this Mar 19, 2024
@Chisomchima Chisomchima marked this pull request as draft March 20, 2024 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants