-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/hpi-schul-cloud/nuxt-client …
…into BC-7511-highlight-course-pages
- Loading branch information
Showing
14 changed files
with
899 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export const useAriaLiveNotifier = () => { | ||
const notifyOnScreenReader = ( | ||
message: string, | ||
importance: "off" | "polite" | "assertive" = "polite" | ||
) => { | ||
// should be a div with aria-live="polite | assertive" attribute | ||
// and should be appended to the upper level of the DOM tree | ||
// the aria-live attribute should be set polite or assertive based on the importance of the message | ||
const element = document.getElementById( | ||
importance === "polite" | ||
? "notify-screen-reader-polite" | ||
: "notify-screen-reader-assertive" | ||
); | ||
|
||
if (!element) { | ||
console.error( | ||
`Element with id 'notify-screen-reader-${importance}' not found` | ||
); | ||
return; | ||
} | ||
|
||
element.innerHTML += `<span>${message}</span>`; | ||
}; | ||
|
||
return { | ||
notifyOnScreenReader, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useAriaLiveNotifier } from "./ariaLiveNotifier"; | ||
|
||
describe("useAriaLiveNotifier", () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = ` | ||
<div> | ||
<div id="notify-screen-reader-polite"></div> | ||
<div id="notify-screen-reader-assertive"></div> | ||
</div>`; | ||
}); | ||
it("should notify on screen reader on 'aria-live=assertive' mode", () => { | ||
jest.useFakeTimers(); | ||
const { notifyOnScreenReader } = useAriaLiveNotifier(); | ||
const element = document.getElementById("notify-screen-reader-assertive"); | ||
const message = "Assertive screen reader message"; | ||
notifyOnScreenReader(message, "assertive"); | ||
|
||
jest.advanceTimersByTime(3000); | ||
expect(element?.innerHTML).toBe(`<span>${message}</span>`); | ||
}); | ||
|
||
it("should notify on screen reader on 'aria-live=polite' mode", () => { | ||
jest.useFakeTimers(); | ||
const { notifyOnScreenReader } = useAriaLiveNotifier(); | ||
const element = document.getElementById("notify-screen-reader-polite"); | ||
const message = "Polite screen reader message"; | ||
notifyOnScreenReader(message, "polite"); | ||
|
||
jest.advanceTimersByTime(3000); | ||
expect(element?.innerHTML).toBe(`<span>${message}</span>`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.