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

a11y: use role=alert for messages from Django and JS #1641

Closed
wants to merge 1 commit into from

Conversation

davidbgk
Copy link
Contributor

@davidbgk davidbgk commented Feb 21, 2024

Also define a custom module+css for alerts (chore).

This is an early stage, more a discussion at this point.
It works with messages from Django and set dynamically via JS.
The old code is still present.

See:

@davidbgk
Copy link
Contributor Author

The only place where we set a message from views is when we clone a map.

@davidbgk davidbgk force-pushed the dom-driven-alerts branch 2 times, most recently from 3616311 to 9a2b4fd Compare February 23, 2024 23:16
@davidbgk
Copy link
Contributor Author

The error level should probably trigger an Infinite duration 🤔

Also define a custom module+css for alerts (chore).
@davidbgk
Copy link
Contributor Author

There are two remaining complex cases where there are buttons and logic within the alert:

  • to send a link upon anonymous map creation
  • in case of conflict with data from the server when we save

@@ -0,0 +1,54 @@
export default class Alerts {
constructor() {
this.alertNode = document.querySelector('[role="alert"]')
Copy link
Member

Choose a reason for hiding this comment

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

nit: Maybe alertNode could be a private property of the object?

}

add(message, level = 'info', duration = 3000) {
this.alertNode.innerHTML = `
Copy link
Member

Choose a reason for hiding this comment

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

Is this replacing all the whole node? How does this plays with multiple alerts being added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's indeed a concern, I was wondering if that case actually happens 🤔


_display(alert) {
const duration = alert.dataset?.duration || 3000
const level = alert.dataset?.level || 'info'
Copy link
Member

Choose a reason for hiding this comment

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

This repeats (in the code) the default behavior values. Maybe use a constant tied to the class instead?

umap/static/umap/js/modules/alerts.js Show resolved Hide resolved
`
const alertDiv = wrapper.firstElementChild
this.alertNode.after(alertDiv)
if (isFinite(duration)) {
Copy link
Member

Choose a reason for hiding this comment

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

Love using Infinity + isFinite 🤝

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.

None yet

2 participants