Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/CharacterAriaLive.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ class CharacterAriaLive extends React.Component<CharacterAriaLiveProps, {}> {
}

componentDidMount() {
// Set aria-hidden
const ariaLiveRegion = document.getElementById(this.props.ariaLiveRegionId);
if (ariaLiveRegion) {
// Set aria-hidden
ariaLiveRegion.setAttribute('aria-hidden', this.props.ariaHidden.toString());
// Clear any existing content (such as when we change language)
ariaLiveRegion.textContent = '';
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/CharacterAriaLive.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,21 @@ function getLiveRegionText() {
return ((document.getElementById('someAriaLiveRegionId'): any): HTMLElement).textContent;
}

function setLiveRegionText(text: string) {
((document.getElementById('someAriaLiveRegionId'): any): HTMLElement).textContent = text;
}

function getLiveRegionAriaHidden() {
return ((document.getElementById('someAriaLiveRegionId'): any): HTMLElement).getAttribute('aria-hidden');
}

test('Existing live region content is cleared when the component is mounted', () => {
setLiveRegionText('content before');
expect(getLiveRegionText()).toBe('content before');
createMountCharacterAriaLive();
expect(getLiveRegionText()).toBe('');
});

test('The live region is updated when the characterState prop is changed', () => {
const wrapper = createMountCharacterAriaLive();
expect(getLiveRegionText()).toBe('');
Expand Down
Loading