Skip to content

Commit

Permalink
feat(components): Make <Text> and <Headline> accessible by allowi…
Browse files Browse the repository at this point in the history
…ng ARIA labelling props (#4194)

* feat(components): Make `<Text>` and `<Headline>` accessible by allowing ARIA labelling props

* Create wet-parents-burn.md
  • Loading branch information
sebald authored Oct 4, 2024
1 parent 9ff555b commit 956982a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .changeset/wet-parents-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@marigold/components": minor
"@marigold/types": minor
---

feat(components): Make `<Text>` and `<Headline>` accessible by allowing ARIA labelling props

`<Text>` and `<Headline>` will no longer cause type errors when ARIA labelling is used (`aria-label`, `id`, ...).
3 changes: 2 additions & 1 deletion packages/components/src/Headline/Headline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {
useClassNames,
useTheme,
} from '@marigold/system';
import type { AriaLabelingProps } from '@marigold/types';

export interface HeadlineProps extends TextAlignProp {
export interface HeadlineProps extends AriaLabelingProps, TextAlignProp {
/**
* Set the color of the headline.
*/
Expand Down
4 changes: 3 additions & 1 deletion packages/components/src/Text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import {
useClassNames,
useTheme,
} from '@marigold/system';
import type { AriaLabelingProps } from '@marigold/types';

// Props
// ---------------
export interface TextProps
extends Omit<RAC.TextProps, 'elementType'>,
extends AriaLabelingProps,
Omit<RAC.TextProps, 'elementType'>,
TextAlignProp,
FontSizeProp,
FontWeightProp,
Expand Down
32 changes: 32 additions & 0 deletions packages/types/src/html.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Properties that are required on elements to enable good accessibility. Make sure
* all components allow these attributes.
*
* Copy/pasted from `@react-types/shared` and added the `id` prop to it.
*/
export interface AriaLabelingProps {
/**
* The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id).
*/
id?: string;

/**
* Defines a string value that labels the current element.
*/
'aria-label'?: string;

/**
* Identifies the element (or elements) that labels the current element.
*/
'aria-labelledby'?: string;

/**
* Identifies the element (or elements) that describes the object.
*/
'aria-describedby'?: string;

/**
* Identifies the element (or elements) that provide a detailed, extended description for the object.
*/
'aria-details'?: string;
}
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from 'type-fest';
export * from './html';
export * from './react';

/**
Expand Down

0 comments on commit 956982a

Please sign in to comment.