Skip to content

Commit efa4d1c

Browse files
committed
GH-548: Clear existing content when mounting CharacterAriaLive
1 parent fb5e454 commit efa4d1c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/CharacterAriaLive.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ class CharacterAriaLive extends React.Component<CharacterAriaLiveProps, {}> {
103103
}
104104

105105
componentDidMount() {
106-
// Set aria-hidden
107106
const ariaLiveRegion = document.getElementById(this.props.ariaLiveRegionId);
108107
if (ariaLiveRegion) {
108+
// Set aria-hidden
109109
ariaLiveRegion.setAttribute('aria-hidden', this.props.ariaHidden.toString());
110+
// Clear any existing content (such as when we change language)
111+
ariaLiveRegion.textContent = '';
110112
}
111113
}
112114

src/CharacterAriaLive.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,21 @@ function getLiveRegionText() {
7171
return ((document.getElementById('someAriaLiveRegionId'): any): HTMLElement).textContent;
7272
}
7373

74+
function setLiveRegionText(text: string) {
75+
((document.getElementById('someAriaLiveRegionId'): any): HTMLElement).textContent = text;
76+
}
77+
7478
function getLiveRegionAriaHidden() {
7579
return ((document.getElementById('someAriaLiveRegionId'): any): HTMLElement).getAttribute('aria-hidden');
7680
}
7781

82+
test('Existing live region content is cleared when the component is mounted', () => {
83+
setLiveRegionText('content before');
84+
expect(getLiveRegionText()).toBe('content before');
85+
createMountCharacterAriaLive();
86+
expect(getLiveRegionText()).toBe('');
87+
});
88+
7889
test('The live region is updated when the characterState prop is changed', () => {
7990
const wrapper = createMountCharacterAriaLive();
8091
expect(getLiveRegionText()).toBe('');

0 commit comments

Comments
 (0)