Skip to content

feat(list): require label #741

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 12 additions & 11 deletions src/components/List/List.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const ListSearchWrapper = () => {
return (
<>
<SearchInput value={query} onChange={setQuery} clearButtonAriaLabel="Clear" />
<List shouldItemFocusBeInset listSize={filtered.length}>
<List aria-label="some list" shouldItemFocusBeInset listSize={filtered.length}>
{filtered &&
filtered.map((item, index) => (
<ListItemBase itemIndex={index} key={item.key} isPadded>
Expand Down Expand Up @@ -290,7 +290,7 @@ const DynamicListWrapper = () => {
List will update in:
<Badge size={18} style={{ display: 'inline' }}>{`${INTERVAL_COUNT - time}`}</Badge>
</Text>
<List listSize={list.length}>
<List aria-label="some list" listSize={list.length}>
{list.map((item, index) => (
<ListItemBase itemIndex={index} key={item.key} isPadded>
{`Item ${item.data}`}
Expand Down Expand Up @@ -335,7 +335,7 @@ const ListWithAriaToolbarWrapper = () => {
return (
<>
<ButtonPill>Before</ButtonPill>
<List listSize={2}>
<List aria-label="some list" listSize={2}>
<ListItemBase size="auto" itemIndex={0} key={0}>
<ListItemBaseSection position="fill">
<Text tagName="p">List Item 0</Text>
Expand All @@ -362,7 +362,7 @@ const ListWithAriaToolbar = Template<unknown>(ListWithAriaToolbarWrapper).bind({
const ListWithButtonsWrapper = () => {
return (
<>
<List shouldFocusOnPress listSize={3}>
<List aria-label="some list" shouldFocusOnPress listSize={3}>
<ListItemBase itemIndex={0} key={0}>
<ButtonPill>0</ButtonPill>
</ListItemBase>
Expand All @@ -386,7 +386,7 @@ const ListWithButtons = Template<unknown>(ListWithButtonsWrapper).bind({});
const ListWithNonFocusableChildrenWrapper = () => {
return (
<>
<List shouldFocusOnPress listSize={2}>
<List aria-label="some list" shouldFocusOnPress listSize={2}>
<ListItemBase size="auto" itemIndex={0} key={0}>
<ButtonPill data-preserve-tabindex tabIndex={-1}>
Non-focusable button
Expand Down Expand Up @@ -436,6 +436,7 @@ const ListWithInitialFocusWrapper = () => {
shouldFocusOnPress
initialFocus={listOne ? 1 : 4}
listSize={listOne ? 2 : 5}
aria-label="some list"
>
{contents}
</List>
Expand All @@ -452,7 +453,7 @@ const ListWithFocusHandlingWrapper = () => {

return (
<>
<List listSize={3}>
<List aria-label="some list" listSize={3}>
<ListItemBase
onFocusWithin={() => {
logMessage('on focus within');
Expand Down Expand Up @@ -510,7 +511,7 @@ const DynamicListWithInitialFocusWrapper = () => {
});

return (
<List initialFocus={numItems - 1} listSize={numItems}>
<List aria-label="some list" initialFocus={numItems - 1} listSize={numItems}>
{Array.from(Array(numItems).keys()).map((index) => (
<ListItemBase itemIndex={index} key={index}>
{`Item ${index}`}
Expand Down Expand Up @@ -539,7 +540,7 @@ const DynamicListWithInitialFocusWrapper2 = () => {
}

return (
<List listSize={showBefore ? 6 : 5}>
<List aria-label="some list" listSize={showBefore ? 6 : 5}>
{showBefore && (
<ListItemBase itemIndex={0} key={3}>
Item 2
Expand Down Expand Up @@ -585,7 +586,7 @@ const DynamicListWithInitialFocusWrapper3 = () => {
}

return (
<List listSize={showBefore ? 7 : 5}>
<List aria-label="some list" listSize={showBefore ? 7 : 5}>
{showBefore && (
<ListItemBase itemIndex={0} key={0}>
Item 0
Expand Down Expand Up @@ -621,7 +622,7 @@ const DynamicListWithInitialFocus3 = Template<unknown>(DynamicListWithInitialFoc

const SingleItemListWrapper = () => {
return (
<List listSize={1}>
<List aria-label="some list" listSize={1}>
<ListItemBase itemIndex={0} key={0}>
Item 0
</ListItemBase>
Expand All @@ -633,7 +634,7 @@ const SingleItemList = Template<unknown>(SingleItemListWrapper).bind({});

const ListWithTextSelectWrapper = () => {
return (
<List shouldFocusOnPress listSize={3}>
<List aria-label="some list" shouldFocusOnPress listSize={3}>
<ListItemBase allowTextSelection itemIndex={0} key={0}>
Item 0
</ListItemBase>
Expand Down
5 changes: 3 additions & 2 deletions src/components/List/List.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AriaRole, CSSProperties, Dispatch, ReactNode, SetStateAction } from 'react';
import { AriaLabelRequired } from '../../utils/a11y';

export type ListOrientation = 'horizontal' | 'vertical';

export interface Props {
export type Props = AriaLabelRequired & {
/**
* Custom class for overriding this component's CSS.
*/
Expand Down Expand Up @@ -65,7 +66,7 @@ export interface Props {
* The index of the item that should be focused initially
*/
initialFocus?: number;
}
};

export interface ListContextValue {
currentFocus?: number;
Expand Down
17 changes: 17 additions & 0 deletions src/components/List/List.typetest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Expect, ExpectExtends, ExpectFalse } from '../../utils/typetest.util';
import { Props } from './List.types';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type cases = [
Expect<ExpectExtends<Props, { listSize: 1; 'aria-label': 'abc' }>>,
Expect<ExpectExtends<Props, { listSize: 1; 'aria-labelledby': 'some-id' }>>,
Expect<ExpectExtends<Props, { listSize: 1; 'aria-label': 'abc'; 'aria-labelledby': 'some-id' }>>,

ExpectFalse<ExpectExtends<Props, { 'aria-label': 'abc' }>>,
ExpectFalse<ExpectExtends<Props, { 'aria-labelledby': 'some-id' }>>,
ExpectFalse<ExpectExtends<Props, { 'aria-label': 'abc'; 'aria-labelledby': 'some-id' }>>,

ExpectFalse<ExpectExtends<Props, { listSize: 1 }>>,

ExpectFalse<ExpectExtends<Props, Record<string, never>>>
];
Loading
Loading