Skip to content

Commit 9bd4416

Browse files
committed
fix section default styling
1 parent 161de54 commit 9bd4416

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

src/A11y.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useRef, useState, useContext } from 'react';
22
import { useThree } from '@react-three/fiber';
33
import useAnnounceStore from './announceStore';
44
import { useA11ySectionContext } from './A11ySection';
5+
import { stylesHiddenButScreenreadable } from './A11yConsts';
56
import { Html } from './Html';
67

78
interface A11yCommonProps {
@@ -104,19 +105,9 @@ export const A11y: React.FC<Props> = ({
104105
...props
105106
}) => {
106107
let constHiddenButScreenreadable = Object.assign(
107-
{
108-
opacity: debug ? 1 : 0,
109-
borderRadius: '50%',
110-
width: '50px',
111-
height: '50px',
112-
overflow: 'hidden',
113-
transform: 'translateX(-50%) translateY(-50%)',
114-
display: 'inline-block',
115-
userSelect: 'none' as const,
116-
WebkitUserSelect: 'none' as const,
117-
WebkitTouchCallout: 'none' as const,
118-
margin: 0,
119-
},
108+
{},
109+
stylesHiddenButScreenreadable,
110+
{ opacity: debug ? 1 : 0 },
120111
a11yElStyle
121112
);
122113

src/A11yConsts.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let stylesHiddenButScreenreadable = {
2+
opacity: 0,
3+
borderRadius: '50%',
4+
width: '50px',
5+
height: '50px',
6+
overflow: 'hidden',
7+
transform: 'translateX(-50%) translateY(-50%)',
8+
display: 'inline-block',
9+
userSelect: 'none' as const,
10+
WebkitUserSelect: 'none' as const,
11+
WebkitTouchCallout: 'none' as const,
12+
margin: 0,
13+
};
14+
15+
export { stylesHiddenButScreenreadable };

src/A11ySection.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import React, {
66
createRef,
77
} from 'react';
88
import { useThree } from '@react-three/fiber';
9+
import { stylesHiddenButScreenreadable } from './A11yConsts';
910

1011
interface Props {
1112
children: React.ReactNode;
@@ -42,6 +43,23 @@ export const A11ySection: React.FC<Props> = ({
4243
el.setAttribute('aria-label', label);
4344
}
4445
el.setAttribute('r3f-a11y', 'true');
46+
el.setAttribute(
47+
'style',
48+
(styles => {
49+
return Object.keys(styles).reduce(
50+
(acc, key) =>
51+
acc +
52+
key
53+
.split(/(?=[A-Z])/)
54+
.join('-')
55+
.toLowerCase() +
56+
':' +
57+
(styles as any)[key] +
58+
';',
59+
''
60+
);
61+
})(stylesHiddenButScreenreadable)
62+
);
4563
if (description) {
4664
if (refpDesc.current === null) {
4765
const pDesc = document.createElement('p');

0 commit comments

Comments
 (0)