Skip to content
Merged
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
48 changes: 41 additions & 7 deletions src/__stories__/list-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export default {
],
control: {type: 'select'},
},
'aria-live': {
options: ['off', 'polite', 'assertive'],
control: {type: 'select'},
},
},
parameters: {
fullScreen: true,
Expand All @@ -72,9 +76,16 @@ type Args = {
disabled: boolean;
danger: boolean;
overInverse: boolean;
'aria-live': 'off' | 'polite' | 'assertive';
'aria-atomic': boolean;
};

const Template: StoryComponent<Args & {boxed?: boolean; inverse?: boolean}> = ({
const Template: StoryComponent<
Args & {
boxed?: boolean;
inverse?: boolean;
}
> = ({
boxed,
headline,
title,
Expand All @@ -91,6 +102,8 @@ const Template: StoryComponent<Args & {boxed?: boolean; inverse?: boolean}> = ({
overInverse,
inverse,
danger,
'aria-live': ariaLive,
'aria-atomic': ariaAtomic,
}) => {
const extraContent = extra ? <Placeholder height={56} /> : undefined;

Expand All @@ -105,26 +118,45 @@ const Template: StoryComponent<Args & {boxed?: boolean; inverse?: boolean}> = ({
controlProps = {href: 'https://example.org', newTab: true, right: null}; // right null removes the chevron
break;
case 'switch':
controlProps = {switch: {defaultValue: true, onChange: () => {}}};
controlProps = {
switch: {
defaultValue: true,
onChange: () => {},
},
};
break;
case 'switch and onPress':
controlProps = {
switch: {defaultValue: true, onChange: () => {}},
switch: {
defaultValue: true,
onChange: () => {},
},
onPress,
};
break;
case 'checkbox':
controlProps = {checkbox: {defaultValue: true, onChange: () => {}}};
controlProps = {
checkbox: {
defaultValue: true,
onChange: () => {},
},
};
break;
case 'checkbox and onPress':
controlProps = {
checkbox: {defaultValue: true, onChange: () => {}},
checkbox: {
defaultValue: true,
onChange: () => {},
},
onPress,
};
break;
case 'checkbox with custom element':
controlProps = {
checkbox: {defaultValue: true, onChange: () => {}},
checkbox: {
defaultValue: true,
onChange: () => {},
},
right: () => (
<div style={{display: 'flex', alignItems: 'center', height: '100%'}}>
<div style={{width: 32, height: 32, borderRadius: '50%', background: 'pink'}} />
Expand Down Expand Up @@ -229,7 +261,7 @@ const Template: StoryComponent<Args & {boxed?: boolean; inverse?: boolean}> = ({

let row = 1;
const list = (
<ListComponent dataAttributes={{testid: 'list'}}>
<ListComponent dataAttributes={{testid: 'list'}} aria-live={ariaLive} aria-atomic={ariaAtomic}>
<RowComponent
headline={headline}
title={title}
Expand Down Expand Up @@ -419,6 +451,8 @@ const defaultArgs = {
disabled: false,
danger: false,
overInverse: false,
'aria-live': 'off' as const,
'aria-atomic': false as const,
};

export const RowListStory: StoryComponent<Args> = (args) => <Template {...args} />;
Expand Down
21 changes: 18 additions & 3 deletions src/__stories__/stack-story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,17 @@ const ComponentThatReturnsNullComponent = () => <Null />;

type Args = {
space: string;
'aria-live': 'off' | 'polite' | 'assertive';
'aria-atomic': boolean;
};

export const Default: StoryComponent<Args> = ({space}) => (
export const Default: StoryComponent<Args> = ({space, 'aria-live': ariaLive, 'aria-atomic': ariaAtomic}) => (
<div style={{height: '100vh'}}>
<Stack space={(Number.isInteger(+space) ? +space : space) as never}>
<Stack
space={(Number.isInteger(+space) ? +space : space) as never}
aria-live={ariaLive}
aria-atomic={ariaAtomic}
>
<ComponentThatReturnsNullComponent />
<Row>One</Row>
{null}
Expand All @@ -54,7 +60,16 @@ export const Default: StoryComponent<Args> = ({space}) => (
);

Default.storyName = 'Stack';

Default.args = {
space: '32',
'aria-live': 'off' as const,
'aria-atomic': false as const,
};
Default.argTypes = {
space: {control: {type: 'select'}},
'aria-live': {
options: ['off', 'polite', 'assertive'],
control: {type: 'select'},
},
'aria-atomic': {control: {type: 'boolean'}},
};
20 changes: 17 additions & 3 deletions src/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -673,25 +673,35 @@ export const Row = React.forwardRef<TouchableElement, RowContentProps>(
)
);

type CommonAccessibilityProps = {
'aria-live'?: 'polite' | 'off' | 'assertive';
'aria-atomic'?: boolean;
};

type RowListProps = {
children: React.ReactNode;
ariaLabelledby?: string;
role?: string;
dataAttributes?: DataAttributes;
};
} & CommonAccessibilityProps;

export const RowList = ({
children,
ariaLabelledby,
role = 'list',
'aria-live': ariaLive = 'off',
'aria-atomic': ariaAtomic = false,
dataAttributes,
}: RowListProps): JSX.Element => {
const childrenContent = React.Children.toArray(children).filter(Boolean);
const lastIndex = childrenContent.length - 1;

return (
<div
role={role}
aria-labelledby={ariaLabelledby}
aria-live={ariaLive}
aria-atomic={ariaAtomic}
{...getPrefixedDataAttributes(dataAttributes, 'RowList')}
>
{childrenContent.map((child, index) => (
Expand All @@ -711,8 +721,8 @@ export const RowList = ({
// danger + isInverse is not allowed
type CommonBoxedRowProps =
| {
danger: true;
isInverse?: false;
danger: true;
}
| {
isInverse?: boolean;
Expand Down Expand Up @@ -752,18 +762,22 @@ type BoxedRowListProps = {
ariaLabelledby?: string;
role?: string;
dataAttributes?: DataAttributes;
};
} & CommonAccessibilityProps;

export const BoxedRowList = ({
children,
ariaLabelledby,
role = 'list',
dataAttributes,
'aria-live': ariaLive = 'off',
'aria-atomic': ariaAtomic = false,
}: BoxedRowListProps): JSX.Element => (
<Stack
space={16}
role={role}
aria-labelledby={ariaLabelledby}
aria-live={ariaLive}
aria-atomic={ariaAtomic}
dataAttributes={{'component-name': 'BoxedRowList', testid: 'BoxedRowList', ...dataAttributes}}
>
{children}
Expand Down
6 changes: 6 additions & 0 deletions src/stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Props = {
className?: string;
role?: string;
'aria-labelledby'?: string;
'aria-live'?: 'polite' | 'off' | 'assertive';
'aria-atomic'?: boolean;
dataAttributes?: DataAttributes;
};

Expand All @@ -48,6 +50,8 @@ const Stack = ({
children,
role,
'aria-labelledby': ariaLabelledby,
'aria-live': ariaLive,
'aria-atomic': ariaAtomic,
dataAttributes,
}: Props): JSX.Element => {
const isFlexStack = typeof space === 'string';
Expand All @@ -58,6 +62,8 @@ const Stack = ({
style={applyCssVars(calcInlineVars(space))}
role={role}
aria-labelledby={ariaLabelledby}
aria-live={ariaLive}
aria-atomic={ariaAtomic}
{...getPrefixedDataAttributes(dataAttributes)}
>
{React.Children.map(children, (child) => (
Expand Down
Loading