Skip to content

Commit

Permalink
fix: detect element disappearance
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Oct 22, 2021
1 parent d814685 commit aa5c3cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .storybook/stories/RoleStatus.stories.ts
Expand Up @@ -126,3 +126,23 @@ export function PartOfContentChanges() {
`
);
}

addStoryName(AriaHiddenChanges, 'PASS');
export function AriaHiddenChanges() {
return createMountToggle(
`
<div role="status">
<span aria-hidden="true">
Hello world
</span>
</div>
`,
`
<div role="status">
<span>
Hello world
</span>
</div>
`
);
}
9 changes: 8 additions & 1 deletion src/capture-announcements.ts
Expand Up @@ -60,7 +60,6 @@ export default function CaptureAnnouncements(options: Options): Restore {
function updateAnnouncements(node: Node) {
const element = getClosestElement(node);
if (!element) return;
if (isHidden(element)) return;

const liveRegion = getClosestLiveRegion(element);

Expand All @@ -71,6 +70,14 @@ export default function CaptureAnnouncements(options: Options): Restore {
const previousText = liveRegions.get(liveRegion);
const newText = getTextContent(liveRegion) || '';

// Update text content when element disappears inside live region
if (isHidden(element)) {
if (previousText) {
liveRegions.set(liveRegion, newText);
}
return;
}

if (previousText !== newText) {
onCapture(newText, politenessSetting);
liveRegions.set(liveRegion, newText);
Expand Down

0 comments on commit aa5c3cf

Please sign in to comment.