Skip to content

Commit 161de54

Browse files
committed
custom Tag v1
1 parent f0e5e39 commit 161de54

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

example/src/App.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,7 @@ export default function App() {
220220
<ambientLight intensity={snap.disabled ? 0.2 : 0.8} />
221221
<group position-y={2}>
222222
<CarrousselAll />
223-
<A11y
224-
role="image"
225-
description="Je suis un test"
226-
>
223+
<A11y role="image" description="Je suis un test">
227224
<SwitchButton position={[-3, 3, 7]} />
228225
</A11y>
229226
<A11y

src/A11y.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type RoleProps =
2525
href?: never;
2626
disabled?: never;
2727
startPressed?: never;
28+
tag?: 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
2829
}
2930
| {
3031
role: 'button';
@@ -34,6 +35,7 @@ type RoleProps =
3435
href?: never;
3536
disabled?: boolean;
3637
startPressed?: never;
38+
tag?: never;
3739
}
3840
| {
3941
role: 'togglebutton';
@@ -43,6 +45,7 @@ type RoleProps =
4345
href?: never;
4446
disabled?: boolean;
4547
startPressed?: boolean;
48+
tag?: never;
4649
}
4750
| {
4851
role: 'link';
@@ -52,6 +55,7 @@ type RoleProps =
5255
href: string;
5356
disabled?: never;
5457
startPressed?: never;
58+
tag?: never;
5559
}
5660
| {
5761
role: 'image';
@@ -61,7 +65,8 @@ type RoleProps =
6165
href?: never;
6266
disabled?: never;
6367
startPressed?: never;
64-
};
68+
tag?: never;
69+
};
6570

6671
type Props = A11yCommonProps & RoleProps;
6772

@@ -94,6 +99,7 @@ export const A11y: React.FC<Props> = ({
9499
debug = false,
95100
a11yElStyle,
96101
startPressed = false,
102+
tag = 'p',
97103
hidden = false,
98104
...props
99105
}) => {
@@ -333,7 +339,7 @@ export const A11y: React.FC<Props> = ({
333339
tabIndex: tabIndex,
334340
}
335341
: null;
336-
if ( role === "image" ) {
342+
if (role === 'image') {
337343
return (
338344
<img
339345
r3f-a11y="true"
@@ -365,9 +371,10 @@ export const A11y: React.FC<Props> = ({
365371
}}
366372
/>
367373
);
368-
}else{
374+
} else {
375+
const Tag = tag;
369376
return (
370-
<p
377+
<Tag
371378
r3f-a11y="true"
372379
{...tabIndexP}
373380
style={Object.assign(
@@ -395,7 +402,7 @@ export const A11y: React.FC<Props> = ({
395402
}}
396403
>
397404
{description}
398-
</p>
405+
</Tag>
399406
);
400407
}
401408
}
@@ -409,6 +416,7 @@ export const A11y: React.FC<Props> = ({
409416
href,
410417
disabled,
411418
startPressed,
419+
tag,
412420
actionCall,
413421
focusCall,
414422
]);

0 commit comments

Comments
 (0)