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

[Accessibility] [Screen Reader] Enable the screen reader to announce when nodes are expanded and collapsed in the JSON tree view #2299

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
width: calc(100% - 10px);
}
}

.aria-region {
position: absolute;
top: -9999px;
overflow: hidden;
}
tonyanziano marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -67,48 +67,51 @@ const mockData = {
};

const mockTreeHTMLText = `
<ul id="rootGroup">
<li>
<div>
<div>▶</div>
</div>
<label><span>root:</span></label>
<span>
<span>
<span>{}</span> 2 keys
</span></span>
<ul id="group1">
<li>
<div>
<div>▶</div>
</div>
<label><span>membersAdded:</span></label>
<span><span><span>[]</span> 1 item</span></span>
<ul id="group2">
<li>
<div role="button" id="actuator">
<div>▶</div>
</div>
<label><span>0:</span></label>
<span>
<div>
<ul id="rootGroup">
<li>
<div>
<div>▶</div>
</div>
<label><span>root:</span></label>
<span>
<span>
<span>{}</span> 2 keys
</span></span>
<ul id="group1">
<li>
<div>
<div>▶</div>
</div>
<label><span>membersAdded:</span></label>
<span><span><span>[]</span> 1 item</span></span>
<ul id="group2">
<li>
<div role="button" id="actuator">
<div>▶</div>
</div>
<label><span>0:</span></label>
<span>
<span>{}</span>
2 keys
<span>
<span>{}</span>
2 keys
</span>
</span>
</span>
<ul id="group3">
<li><label><span>id:</span></label><span>"1"</span></li>
<li><label><span>name:</span></label><span>"Bot"</span>
</li>
</ul>
</li>
</ul>
</li>
<li><label><span>type:</span></label><span>"conversationUpdate"</span>
</li>
</ul>
</li>
</ul>`;
<ul id="group3">
<li><label><span>id:</span></label><span>"1"</span></li>
<li><label><span>name:</span></label><span>"Bot"</span>
</li>
</ul>
</li>
</ul>
</li>
<li><label><span>type:</span></label><span>"conversationUpdate"</span>
</li>
</ul>
</li>
</ul>
<div id="ariaRegion" role="region" aria-live="polite" className={styles.ariaRegion}>text content</div>
</div>`;

let jsonViewerWrapper;
let jsonViewer;
Expand All @@ -117,6 +120,7 @@ describe('The JsonViewer', () => {
beforeAll(() => {
jsonViewerWrapper = mount(<CollapsibleJsonViewer data={mockData} themeName={'high-contrast'} />);
jsonViewer = jsonViewerWrapper.find(CollapsibleJsonViewer).instance();
document.body.innerHTML = mockTreeHTMLText;
});

it('should render with data and a theme', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class CollapsibleJsonViewer extends Component<CollapsibleJsonViewerProps,
return (
<div ref={this.jsonTreeContainerRef} className={styles.collapsibleJsonViewer}>
<JSONTree data={data} theme={themeNameToViewerThemeName[themeName]} invertTheme={false} {...jsonTreeProps} />
<div id="ariaRegion" role="region" aria-live="polite" className={styles.ariaRegion} />
</div>
);
}
Expand Down Expand Up @@ -186,6 +187,10 @@ export class CollapsibleJsonViewer extends Component<CollapsibleJsonViewerProps,
const proposedAriaExpandedValue = !(ul.getAttribute('aria-expanded') === 'true');
ul.setAttribute('aria-expanded', proposedAriaExpandedValue.toString());
target.setAttribute('aria-expanded', proposedAriaExpandedValue.toString());
// Announce the expanded/collapsed state
const ariaRegion = document.getElementById('ariaRegion');
const newState = proposedAriaExpandedValue ? 'Node expanded' : 'Node collapsed';
ariaRegion.textContent = ariaRegion.textContent.indexOf('.') > -1 ? newState : newState.concat('.');
tonyanziano marked this conversation as resolved.
Show resolved Hide resolved
};

private focusNext(event: KeyboardEvent): void {
Expand Down