Skip to content

Commit cb24dbb

Browse files
[Layout] Add suport for passing in aria attributes (#7767)
### WHY are these changes introduced? Supports #7354 which needs to be able to pass in aria attributes ### WHAT is this pull request doing? - adds support for aria attributes to `Box` and `AlphaStack` Co-authored-by: Aaron Casanova <32409546+aaronccasanova@users.noreply.github.com>
1 parent e0c64cd commit cb24dbb

File tree

5 files changed

+2401
-2367
lines changed

5 files changed

+2401
-2367
lines changed

.changeset/slow-rocks-press.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/polaris': minor
3+
'polaris.shopify.com': patch
4+
---
5+
6+
Updated `Box` and `AlphaStack` to accept aria attributes

polaris-react/src/components/AlphaStack/AlphaStack.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Element = 'div' | 'ul' | 'ol' | 'fieldset';
1616

1717
type Gap = ResponsiveProp<SpacingSpaceScale>;
1818

19-
export interface AlphaStackProps {
19+
export interface AlphaStackProps extends React.AriaAttributes {
2020
children?: React.ReactNode;
2121
/** HTML Element type
2222
* @default 'div'
@@ -34,6 +34,8 @@ export interface AlphaStackProps {
3434
* @default '4'
3535
*/
3636
gap?: Gap;
37+
/** HTML id attribute */
38+
id?: string;
3739
}
3840

3941
export const AlphaStack = ({
@@ -42,6 +44,8 @@ export const AlphaStack = ({
4244
align = 'start',
4345
fullWidth = false,
4446
gap = '4',
47+
id,
48+
...restProps
4549
}: AlphaStackProps) => {
4650
const className = classNames(
4751
styles.AlphaStack,
@@ -59,6 +63,7 @@ export const AlphaStack = ({
5963
{
6064
className,
6165
style: sanitizeCustomProperties(style),
66+
...restProps,
6267
},
6368
children,
6469
);

polaris-react/src/components/Box/Box.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type BackgroundColors =
6868
| ColorsActionTokenAlias
6969
| ColorsSurfaceTokenAlias;
7070

71-
export interface BoxProps {
71+
export interface BoxProps extends React.AriaAttributes {
7272
children?: React.ReactNode;
7373
/** HTML Element type
7474
* @default 'div'
@@ -216,6 +216,7 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
216216
insetInlineEnd,
217217
zIndex,
218218
opacity,
219+
...restProps
219220
},
220221
ref,
221222
) => {
@@ -326,6 +327,7 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
326327
id,
327328
ref,
328329
style: sanitizeCustomProperties(style),
330+
...restProps,
329331
},
330332
children,
331333
);

polaris-react/src/components/Box/tests/Box.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,17 @@ describe('Box', () => {
111111
}) as React.CSSProperties,
112112
});
113113
});
114+
115+
it('renders the aria attributes that matches the aria attributes passed in', () => {
116+
const box = mountWithApp(
117+
<Box aria-required aria-describedby="test">
118+
{children}
119+
</Box>,
120+
);
121+
122+
expect(box).toContainReactComponent('div', {
123+
'aria-required': true,
124+
'aria-describedby': 'test',
125+
});
126+
});
114127
});

0 commit comments

Comments
 (0)