Skip to content

Commit 07acfbe

Browse files
author
Kubit
committed
Add aria props to PillV2
1 parent c311b77 commit 07acfbe

File tree

4 files changed

+88
-5
lines changed

4 files changed

+88
-5
lines changed

src/components/pillV2/pillStandAlone.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import React from 'react';
32

43
import { useId } from '@/hooks/useId/useId';
54
import { InputTypeType } from '@/types/inputType/inputType';
5+
import { pickAriaProps } from '@/utils/aria/aria';
66

77
import { ROLES } from '../../types/role/role';
88
import { ButtonType } from '../button/types/type';
@@ -22,13 +22,14 @@ const PillStandAloneComponent = (
2222
{ dataTestId = 'pill', type = PillType.BUTTON, ...props }: IPillStandAlone,
2323
ref: React.ForwardedRef<HTMLDivElement> | undefined | null
2424
): JSX.Element => {
25+
const ariaProps = pickAriaProps(props);
2526
const id = useId('pill');
2627
const pillContentId = `${id}-content`;
2728

2829
return (
2930
<PillRootContainerStyled
30-
ref={ref as any}
31-
aria-controls={props['aria-controls']}
31+
ref={ref}
32+
{...ariaProps}
3233
aria-selected={type === PillType.TAB ? props.selected : undefined}
3334
as={[PillType.BUTTON, PillType.TAB].includes(type) ? PillAsButton : undefined}
3435
data-testid={dataTestId}

src/components/pillV2/stories/argtypes.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,72 @@ export const argtypes = (
169169
category: CATEGORY_CONTROL.TESTING,
170170
},
171171
},
172+
['aria-label']: {
173+
description: 'Text applied to aria-label property of input component',
174+
type: { name: 'string' },
175+
control: { type: 'text' },
176+
table: {
177+
type: {
178+
summary: 'string',
179+
},
180+
category: CATEGORY_CONTROL.ACCESIBILITY,
181+
},
182+
},
183+
['aria-labelledby']: {
184+
description: 'Text applied to aria-labelledby property of input component',
185+
type: { name: 'string' },
186+
control: { type: 'text' },
187+
table: {
188+
type: {
189+
summary: 'string',
190+
},
191+
category: CATEGORY_CONTROL.ACCESIBILITY,
192+
},
193+
},
194+
['aria-describedby']: {
195+
description: 'Text applied to aria-describedby property of input component',
196+
type: { name: 'string' },
197+
control: { type: 'text' },
198+
table: {
199+
type: {
200+
summary: 'string',
201+
},
202+
category: CATEGORY_CONTROL.ACCESIBILITY,
203+
},
204+
},
205+
['aria-pressed']: {
206+
description: 'Text applied to aria-describedby property of input component',
207+
type: { name: 'string' },
208+
control: { type: 'text' },
209+
table: {
210+
type: {
211+
summary: 'string',
212+
},
213+
category: CATEGORY_CONTROL.ACCESIBILITY,
214+
},
215+
},
216+
['aria-disabled']: {
217+
description: 'Text applied to aria-describedby property of input component',
218+
type: { name: 'string' },
219+
control: { type: 'text' },
220+
table: {
221+
type: {
222+
summary: 'string',
223+
},
224+
category: CATEGORY_CONTROL.ACCESIBILITY,
225+
},
226+
},
227+
['aria-expanded']: {
228+
description: 'Apply to aria-expanded property of input component',
229+
type: { name: 'string' },
230+
control: { type: 'text' },
231+
table: {
232+
type: {
233+
summary: 'string',
234+
},
235+
category: CATEGORY_CONTROL.ACCESIBILITY,
236+
},
237+
},
172238
ctv: {
173239
description: 'Object used for update variant styles',
174240
type: { name: 'object' },

src/components/pillV2/types/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ export type {
44
PillSizePropsStylesType as PillSizePropsStylesTypeV2,
55
PillPropsStylesType as PillPropsStylesTypeV2,
66
} from './pillTheme';
7-
export type { IPill as IPillV2, PillLabelType as PillLabelTypeV2 } from './pill';
7+
export type {
8+
IPill as IPillV2,
9+
PillLabelType as PillLabelTypeV2,
10+
PillAriaAttributes as PillAriaAttributesV2,
11+
} from './pill';
812
export { PillStateType as PillStateTypeV2 } from './pillStateType';
913
export { PillType as PillTypeV2 } from './pillType';

src/components/pillV2/types/pill.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,19 @@ export type PillLabelType = Omit<IText<string>, 'children'> & {
1111
content?: ReactNode;
1212
};
1313

14-
export interface IPillStandAlone {
14+
export type PillAriaAttributes = Pick<
15+
React.AriaAttributes,
16+
| 'aria-label'
17+
| 'aria-labelledby'
18+
| 'aria-checked'
19+
| 'aria-describedby'
20+
| 'aria-pressed'
21+
| 'aria-disabled'
22+
| 'aria-controls'
23+
| 'aria-expanded'
24+
>;
25+
26+
export interface IPillStandAlone extends PillAriaAttributes {
1527
styles?: PillPropsStylesType;
1628
leftIcon?: IElementOrIcon;
1729
label?: PillLabelType;

0 commit comments

Comments
 (0)