-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: AccordionPanelのkeydownイベントリスナーをTriggerに移動
- Loading branch information
Showing
4 changed files
with
158 additions
and
63 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
packages/smarthr-ui/src/components/AccordionPanel/AccordionPanel.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { userEvent } from '@storybook/test' | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import { config } from 'react-transition-group' | ||
|
||
import { Fieldset } from '../Fieldset' | ||
import { RadioButton } from '../RadioButton' | ||
|
||
import { AccordionPanel } from './AccordionPanel' | ||
import { AccordionPanelContent } from './AccordionPanelContent' | ||
import { AccordionPanelItem } from './AccordionPanelItem' | ||
import { AccordionPanelTrigger } from './AccordionPanelTrigger' | ||
|
||
describe('AccordionPanel', () => { | ||
beforeAll(() => { | ||
config.disabled = true | ||
}) | ||
|
||
afterAll(() => { | ||
config.disabled = false | ||
}) | ||
|
||
test('アコーディオン内に配置したラジオボタンをキーボード操作できる', async () => { | ||
render( | ||
<form> | ||
<AccordionPanel> | ||
<AccordionPanelItem name="accordion-panel-1"> | ||
<AccordionPanelTrigger>アコーディオンパネル1</AccordionPanelTrigger> | ||
<AccordionPanelContent> | ||
<Fieldset title="ラジオボタン" innerMargin={0.5}> | ||
<RadioButton name="radio1">ラジオボタン1-1</RadioButton> | ||
<RadioButton name="radio1">ラジオボタン1-2</RadioButton> | ||
</Fieldset> | ||
</AccordionPanelContent> | ||
</AccordionPanelItem> | ||
|
||
<AccordionPanelItem name="accordion-panel-2"> | ||
<AccordionPanelTrigger>アコーディオンパネル2</AccordionPanelTrigger> | ||
<AccordionPanelContent> | ||
<Fieldset title="ラジオボタン" innerMargin={0.5}> | ||
<RadioButton name="radio2">ラジオボタン2-1</RadioButton> | ||
<RadioButton name="radio2">ラジオボタン2-2</RadioButton> | ||
</Fieldset> | ||
</AccordionPanelContent> | ||
</AccordionPanelItem> | ||
</AccordionPanel> | ||
</form>, | ||
) | ||
|
||
await userEvent.keyboard('[Tab]') | ||
await userEvent.keyboard('[Space]') | ||
expect(screen.getByRole('button', { name: 'アコーディオンパネル1' })).toHaveFocus() | ||
|
||
await userEvent.keyboard('[Tab]') | ||
await userEvent.keyboard('[Space]') | ||
expect(screen.getByRole('radio', { name: 'ラジオボタン1-1' })).toHaveFocus() | ||
expect(screen.getByRole('radio', { name: 'ラジオボタン1-1' })).toBeChecked() | ||
|
||
await userEvent.keyboard('[ArrowRight]') | ||
await userEvent.keyboard('[Space]') | ||
expect(screen.getByRole('radio', { name: 'ラジオボタン1-2' })).toHaveFocus() | ||
expect(screen.getByRole('radio', { name: 'ラジオボタン1-2' })).toBeChecked() | ||
|
||
await userEvent.keyboard('[ArrowLeft]') | ||
await userEvent.keyboard('[Space]') | ||
expect(screen.getByRole('radio', { name: 'ラジオボタン1-1' })).toHaveFocus() | ||
expect(screen.getByRole('radio', { name: 'ラジオボタン1-1' })).toBeChecked() | ||
}) | ||
|
||
test('矢印キーでAccordionPanelItem間を移動できる', async () => { | ||
render( | ||
<form> | ||
<AccordionPanel> | ||
<AccordionPanelItem name="accordion-panel-1"> | ||
<AccordionPanelTrigger>アコーディオンパネル1</AccordionPanelTrigger> | ||
<AccordionPanelContent> | ||
<Fieldset title="ラジオボタン" innerMargin={0.5}> | ||
<RadioButton name="radio1">ラジオボタン1-1</RadioButton> | ||
<RadioButton name="radio1">ラジオボタン1-2</RadioButton> | ||
</Fieldset> | ||
</AccordionPanelContent> | ||
</AccordionPanelItem> | ||
|
||
<AccordionPanelItem name="accordion-panel-2"> | ||
<AccordionPanelTrigger>アコーディオンパネル2</AccordionPanelTrigger> | ||
<AccordionPanelContent> | ||
<Fieldset title="ラジオボタン" innerMargin={0.5}> | ||
<RadioButton name="radio2">ラジオボタン2-1</RadioButton> | ||
<RadioButton name="radio2">ラジオボタン2-2</RadioButton> | ||
</Fieldset> | ||
</AccordionPanelContent> | ||
</AccordionPanelItem> | ||
</AccordionPanel> | ||
</form>, | ||
) | ||
|
||
await userEvent.keyboard('[Tab]') | ||
await userEvent.keyboard('[Space]') | ||
expect(screen.getByRole('button', { name: 'アコーディオンパネル1' })).toHaveFocus() | ||
|
||
await userEvent.keyboard('[ArrowDown]') | ||
expect(screen.getByRole('button', { name: 'アコーディオンパネル2' })).toHaveFocus() | ||
|
||
await userEvent.keyboard('[ArrowUp]') | ||
expect(screen.getByRole('button', { name: 'アコーディオンパネル1' })).toHaveFocus() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters