Skip to content

Commit be87e6e

Browse files
authored
Merge pull request #36 from openscript/master
feat: add role attribute
2 parents a93135b + 2e4f53f commit be87e6e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

example/pages/accessibility.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ You can also add an `aria-label` directly on the `<TypeAnimation />` component t
5454
```tsx {2}
5555
<TypeAnimation
5656
aria-label="We produce food for Mice, Hamsters, Guinea Pigs and Chinchillas"
57+
role="marquee"
5758
sequence={[
5859
// Same String at the start will only be typed once, initially
5960
'We produce food for Mice',
@@ -70,6 +71,8 @@ You can also add an `aria-label` directly on the `<TypeAnimation />` component t
7071
/>
7172
```
7273

74+
Setting an `aria-label` requires setting a `role` as well. The role [`marquee`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/marquee_role) is probably the most suitable for this situation.
75+
7376
By applying an `aria-label`, the dynamically typed contents of your sequence will automatically be wrapped in a `<span/>` with `aria-hidden="true"` and removed from the accessibility tree:
7477

7578
```html {aria-hidden="true"}

src/components/TypeAnimation/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const TypeAnimation = forwardRef<
2626
},
2727
ref: React.ForwardedRef<HTMLElementTagNameMap[Wrapper]>
2828
) => {
29-
const { 'aria-label': ariaLabel, 'aria-hidden': ariaHidden } = rest;
29+
const { 'aria-label': ariaLabel, 'aria-hidden': ariaHidden, role } = rest;
3030

3131
if (!deletionSpeed) {
3232
deletionSpeed = speed;
@@ -108,6 +108,7 @@ const TypeAnimation = forwardRef<
108108
<WrapperEl
109109
aria-hidden={ariaHidden}
110110
aria-label={ariaLabel}
111+
role={role}
111112
style={style}
112113
className={finalClassName}
113114
children={

0 commit comments

Comments
 (0)