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

Addon A11y: Toggle default focus of "tests completed" button #24446

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions code/addons/a11y/src/components/A11YPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import { styled } from '@storybook/theming';

import { ActionBar, Icons, ScrollArea } from '@storybook/components';

import type { AxeResults } from 'axe-core';
import { useChannel, useParameter, useStorybookState } from '@storybook/manager-api';
import type { AxeResults } from 'axe-core';

import { Report } from './Report';

import { Tabs } from './Tabs';

import { useA11yContext } from './A11yContext';
import { EVENTS } from '../constants';
import type { A11yParameters } from '../params';
import { useA11yContext } from './A11yContext';

export enum RuleType {
VIOLATION,
Expand Down Expand Up @@ -112,6 +112,7 @@ export const A11YPanel: React.FC = () => {
</>
),
onClick: handleManual,
defaultFocus: true,
},
],
[status, handleManual]
Expand Down
25 changes: 16 additions & 9 deletions code/ui/components/src/components/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Container = styled.div(({ theme }) => ({
zIndex: 1,
}));

export const ActionButton = styled.button<{ disabled: boolean }>(
export const ActionButton = styled.button<{ disabled: boolean; defaultFocus: boolean }>(
({ theme }) => ({
margin: 0,
border: '0 none',
Expand Down Expand Up @@ -41,16 +41,16 @@ export const ActionButton = styled.button<{ disabled: boolean }>(
borderLeft: `1px solid ${theme.appBorderColor}`,
borderRadius: 0,
},

'&:focus': {
boxShadow: `${theme.color.secondary} 0 -3px 0 0 inset`,
outline: '0 none',
},
}),
({ disabled }) =>
disabled && {
cursor: 'not-allowed',
opacity: 0.5,
},
({ theme, defaultFocus }) =>
!defaultFocus && {
boxShadow: `${theme.color.secondary} 0 -3px 0 0 inset`,
outline: '0 none',
}
);
ActionButton.displayName = 'ActionButton';
Expand All @@ -60,6 +60,7 @@ export interface ActionItem {
className?: string;
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
disabled?: boolean;
defaultFocus?: boolean;
}

export interface ActionBarProps {
Expand All @@ -68,9 +69,15 @@ export interface ActionBarProps {

export const ActionBar: FC<ActionBarProps> = ({ actionItems, ...props }) => (
<Container {...props}>
{actionItems.map(({ title, className, onClick, disabled }, index: number) => (
// eslint-disable-next-line react/no-array-index-key
<ActionButton key={index} className={className} onClick={onClick} disabled={disabled}>
{actionItems.map(({ title, className, onClick, disabled, defaultFocus }, index: number) => (
<ActionButton
// eslint-disable-next-line react/no-array-index-key
key={index}
className={className}
onClick={onClick}
disabled={disabled}
defaultFocus={defaultFocus}
>
{title}
</ActionButton>
))}
Expand Down