Skip to content

Commit

Permalink
Fix tab buttons missing role, aria-selected requires it
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Aug 19, 2024
1 parent 08ab053 commit e7e470a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
2 changes: 2 additions & 0 deletions scss/bitstyles/atoms/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export default ({
children,
colorVariant = [],
shapeVariant = [],
role = undefined,
ariaLabel = undefined,
ariaPressed = false,
ariaDisabled = false,
Expand Down Expand Up @@ -34,6 +35,7 @@ export default ({
button.classList.add(cls);
});
if (element === 'button') button.type = 'button';
if (role) button.setAttribute('role', role);
if (ariaLabel) button.setAttribute('aria-label', ariaLabel);
if (ariaPressed) button.setAttribute('aria-pressed', ariaPressed);
if (ariaDisabled) button.setAttribute('aria-disabled', ariaDisabled);
Expand Down
39 changes: 30 additions & 9 deletions scss/bitstyles/atoms/button/button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,21 @@ DefaultOutline.parameters = {
],
};

const baseTabArgs = {
colorVariant: ['tab'],
role: 'tab',
};

const TabDecorator = (story) => {
const decorator = document.createElement('ul');
decorator.setAttribute('role', 'tablist');
decorator.appendChild(story());
return decorator;
};

export const DefaultTab = Template.bind({});
DefaultTab.args = { colorVariant: ['tab'] };
DefaultTab.decorators = [TabDecorator];
DefaultTab.args = { ...baseTabArgs };
DefaultTab.parameters = {
zeplinLink: [
{
Expand Down Expand Up @@ -771,7 +784,8 @@ OutlinePressed.parameters = {
};

export const TabPressed = Template.bind({});
TabPressed.args = { colorVariant: ['tab'], ariaCurrent: 'page' };
TabPressed.decorators = [TabDecorator];
TabPressed.args = { ...baseTabArgs, ariaCurrent: 'page' };
TabPressed.parameters = {
zeplinLink:
'https://app.zeplin.io/styleguide/63079b90d0bf4a646c46c227/components?coid=640094b52890b84043f89ba4',
Expand Down Expand Up @@ -815,7 +829,8 @@ OutlineDisabled.parameters = {
};

export const TabDisabled = Template.bind({});
TabDisabled.args = { colorVariant: ['tab'], disabled: true };
TabDisabled.decorators = [TabDecorator];
TabDisabled.args = { ...baseTabArgs, disabled: true };
TabDisabled.parameters = {
zeplinLink:
'https://app.zeplin.io/styleguide/63079b90d0bf4a646c46c227/components?coid=640094b30ee0b5408ad023fd',
Expand Down Expand Up @@ -930,7 +945,8 @@ OutlineAnchor.parameters = {
};

export const TabAnchor = Template.bind({});
TabAnchor.args = { colorVariant: ['tab'], element: 'anchor' };
TabAnchor.decorators = [TabDecorator];
TabAnchor.args = { ...baseTabArgs, element: 'anchor' };
TabAnchor.parameters = {
zeplinLink: [
{
Expand All @@ -949,8 +965,9 @@ TabAnchor.parameters = {
};

export const TabAnchorPressed = Template.bind({});
TabAnchorPressed.decorators = [TabDecorator];
TabAnchorPressed.args = {
colorVariant: ['tab'],
...baseTabArgs,
element: 'anchor',
ariaCurrent: 'page',
};
Expand Down Expand Up @@ -1087,8 +1104,9 @@ OutlineAnchorDisabled.parameters = {
};

export const TabAnchorDisabled = Template.bind({});
TabAnchorDisabled.decorators = [TabDecorator];
TabAnchorDisabled.args = {
colorVariant: ['tab'],
...baseTabArgs,
ariaDisabled: true,
element: 'a',
};
Expand Down Expand Up @@ -1144,8 +1162,9 @@ DangerOutlineAnchorDisabled.parameters = {
// ***** Icon-only tab buttons ****************** //

export const TabIconOnlyBase = Template.bind({});
TabIconOnlyBase.decorators = [TabDecorator];
TabIconOnlyBase.args = {
colorVariant: ['tab'],
...baseTabArgs,
shapeVariant: ['square'],
children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-plus"></use></svg><span class="u-sr-only">Add</span>`,
};
Expand All @@ -1167,8 +1186,9 @@ TabIconOnlyBase.parameters = {
};

export const TabIconOnlySelected = Template.bind({});
TabIconOnlySelected.decorators = [TabDecorator];
TabIconOnlySelected.args = {
colorVariant: ['tab'],
...baseTabArgs,
shapeVariant: ['square'],
children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-plus"></use></svg><span class="u-sr-only">Add</span>`,
ariaSelected: true,
Expand All @@ -1179,8 +1199,9 @@ TabIconOnlySelected.parameters = {
};

export const TabIconOnlyDisabled = Template.bind({});
TabIconOnlyDisabled.decorators = [TabDecorator];
TabIconOnlyDisabled.args = {
colorVariant: ['tab'],
...baseTabArgs,
shapeVariant: ['square'],
children: `<svg width="20" height="20" class="a-icon a-icon--m" aria-hidden="true" focusable="false"><use xlink:href="${icons}#icon-plus"></use></svg><span class="u-sr-only">Add</span>`,
disabled: true,
Expand Down
2 changes: 1 addition & 1 deletion scss/bitstyles/organisms/page-header/PageHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ breadCrumbsMenu.innerHTML = `
</svg>
</li>`;

export const header = document.createElement('header');
export const header = document.createElement('div');
header.innerHTML = `
<div class="u-flex u-justify-between u-flex-wrap u-items-center u-margin-m-y">
<div class="u-flex u-flex-wrap u-items-center">
Expand Down

0 comments on commit e7e470a

Please sign in to comment.