Skip to content

Commit

Permalink
custom Tag v1
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaricBaraou committed Jun 27, 2021
1 parent f0e5e39 commit 161de54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 1 addition & 4 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,7 @@ export default function App() {
<ambientLight intensity={snap.disabled ? 0.2 : 0.8} />
<group position-y={2}>
<CarrousselAll />
<A11y
role="image"
description="Je suis un test"
>
<A11y role="image" description="Je suis un test">
<SwitchButton position={[-3, 3, 7]} />
</A11y>
<A11y
Expand Down
18 changes: 13 additions & 5 deletions src/A11y.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type RoleProps =
href?: never;
disabled?: never;
startPressed?: never;
tag?: 'p' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
}
| {
role: 'button';
Expand All @@ -34,6 +35,7 @@ type RoleProps =
href?: never;
disabled?: boolean;
startPressed?: never;
tag?: never;
}
| {
role: 'togglebutton';
Expand All @@ -43,6 +45,7 @@ type RoleProps =
href?: never;
disabled?: boolean;
startPressed?: boolean;
tag?: never;
}
| {
role: 'link';
Expand All @@ -52,6 +55,7 @@ type RoleProps =
href: string;
disabled?: never;
startPressed?: never;
tag?: never;
}
| {
role: 'image';
Expand All @@ -61,7 +65,8 @@ type RoleProps =
href?: never;
disabled?: never;
startPressed?: never;
};
tag?: never;
};

type Props = A11yCommonProps & RoleProps;

Expand Down Expand Up @@ -94,6 +99,7 @@ export const A11y: React.FC<Props> = ({
debug = false,
a11yElStyle,
startPressed = false,
tag = 'p',
hidden = false,
...props
}) => {
Expand Down Expand Up @@ -333,7 +339,7 @@ export const A11y: React.FC<Props> = ({
tabIndex: tabIndex,
}
: null;
if ( role === "image" ) {
if (role === 'image') {
return (
<img
r3f-a11y="true"
Expand Down Expand Up @@ -365,9 +371,10 @@ export const A11y: React.FC<Props> = ({
}}
/>
);
}else{
} else {
const Tag = tag;
return (
<p
<Tag
r3f-a11y="true"
{...tabIndexP}
style={Object.assign(
Expand Down Expand Up @@ -395,7 +402,7 @@ export const A11y: React.FC<Props> = ({
}}
>
{description}
</p>
</Tag>
);
}
}
Expand All @@ -409,6 +416,7 @@ export const A11y: React.FC<Props> = ({
href,
disabled,
startPressed,
tag,
actionCall,
focusCall,
]);
Expand Down

0 comments on commit 161de54

Please sign in to comment.