Skip to content

Commit 66a0b03

Browse files
committed
add a11y demo
1 parent f1d1564 commit 66a0b03

File tree

11 files changed

+3410
-23
lines changed

11 files changed

+3410
-23
lines changed

7/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

7/src/App.tsx

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
1-
import { Popover } from './Popover'; // Assuming Popover is in the same directory
1+
import { useState } from 'react';
2+
import {
3+
useFloating,
4+
useRole, // 追加
5+
useInteractions, // 追加
6+
} from '@floating-ui/react';
27

38
function App() {
49

10+
const [ isOpen, setIsOpen ] = useState( false );
11+
const { refs, floatingStyles, context } = useFloating( {
12+
open: isOpen,
13+
onOpenChange: setIsOpen,
14+
} );
15+
16+
const role = useRole( context, { role: 'dialog' } ); // 追加
17+
18+
const { getReferenceProps, getFloatingProps } = useInteractions( [
19+
role,
20+
] );
21+
522
return (
623
<>
7-
Basic React App
8-
<div style={ { height: 'calc(100vh - 60px)' } }></div>
9-
10-
<Popover
11-
trigger={
12-
<button type="button">Click me!</button>
13-
}
24+
Basic React App<br />
25+
<button
26+
type="button"
27+
ref={ refs.setReference }
28+
onClick={ () => setIsOpen( ! isOpen ) }
29+
{ ...getReferenceProps() } // 追加
1430
>
15-
ポップオーバー内容
16-
</Popover>
31+
Click Me!
32+
</button>
1733

18-
<div style={ { display: 'flex', justifyContent: 'end' } }>
19-
<Popover
20-
trigger={
21-
<button type="button">Click me, too!</button>
22-
}
34+
{ isOpen && (
35+
<div
36+
ref={ refs.setFloating }
37+
style={ { ...floatingStyles, zIndex: 100, background: '#ccc' } }
38+
{ ...getFloatingProps() } // 追加
2339
>
24-
右端のポップオーバー内容
25-
</Popover>
26-
</div>
27-
28-
<div style={ { height: '100vh' } }></div>
40+
Popover
41+
</div>
42+
) }
2943
</>
3044
);
3145
}

8/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

8/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="ja">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + React + TS</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>

0 commit comments

Comments
 (0)