Unverified Commit a4674beb authored by Lyza Gardner's avatar Lyza Gardner Committed by GitHub

Add annotation counts to `aria-label` for tab selection (#2190)

Co-authored-by: 's avatarKyle Keating <kkeating@hypothes.is>
parent 095bd446
...@@ -27,6 +27,8 @@ function Tab({ ...@@ -27,6 +27,8 @@ function Tab({
} }
}; };
const title = count > 0 ? `${label} (${count} available)` : label;
return ( return (
<button <button
className={classnames('selection-tabs__type', { className={classnames('selection-tabs__type', {
...@@ -39,8 +41,8 @@ function Tab({ ...@@ -39,8 +41,8 @@ function Tab({
onMouseDown={selectTab} onMouseDown={selectTab}
role="tab" role="tab"
tabIndex="0" tabIndex="0"
title={label} title={title}
aria-label={label} aria-label={title}
aria-selected={isSelected.toString()} aria-selected={isSelected.toString()}
> >
{children} {children}
......
...@@ -106,18 +106,32 @@ describe('SelectionTabs', function () { ...@@ -106,18 +106,32 @@ describe('SelectionTabs', function () {
assert.equal(tabs.length, 2); assert.equal(tabs.length, 2);
}); });
it('should render `title` and `aria-label` attributes for tab buttons', () => { it('should render `title` and `aria-label` attributes for tab buttons, with counts', () => {
fakeStore.orphanCount.returns(1); fakeStore.orphanCount.returns(1);
const wrapper = createComponent({}); const wrapper = createComponent({});
const tabs = wrapper.find('button'); const tabs = wrapper.find('button');
assert.equal(tabs.at(0).prop('aria-label'), 'Annotations'); assert.equal(
assert.equal(tabs.at(0).prop('title'), 'Annotations'); tabs.at(0).prop('aria-label'),
'Annotations (123 available)'
);
assert.equal(tabs.at(0).prop('title'), 'Annotations (123 available)');
assert.equal(tabs.at(1).prop('aria-label'), 'Page notes (456 available)');
assert.equal(tabs.at(1).prop('title'), 'Page notes (456 available)');
assert.equal(tabs.at(2).prop('aria-label'), 'Orphans (1 available)');
assert.equal(tabs.at(2).prop('title'), 'Orphans (1 available)');
});
it('should not render count in `title` and `aria-label` for page notes tab if there are no page notes', () => {
fakeStore.noteCount.returns(0);
const wrapper = createComponent({});
const tabs = wrapper.find('button');
assert.equal(tabs.at(1).prop('aria-label'), 'Page notes'); assert.equal(tabs.at(1).prop('aria-label'), 'Page notes');
assert.equal(tabs.at(1).prop('title'), 'Page notes'); assert.equal(tabs.at(1).prop('title'), 'Page notes');
assert.equal(tabs.at(2).prop('aria-label'), 'Orphans');
assert.equal(tabs.at(2).prop('title'), 'Orphans');
}); });
it('should show the clean theme when settings contains the clean theme option', function () { it('should show the clean theme when settings contains the clean theme option', function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment