-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'try/state-in-context-use-hook' of https://github.com/re…
…akit/reakit into try/state-in-context-use-hook
- Loading branch information
Showing
15 changed files
with
592 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
/Role | ||
/Rover | ||
/Separator | ||
/StateContext | ||
/Tab | ||
/Tabbable | ||
/Toolbar | ||
|
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
236 changes: 236 additions & 0 deletions
236
packages/reakit/src/Combobox/__examples__/AccessibleComboboxContext/__tests__/index-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,236 @@ | ||
import * as React from "react"; | ||
import { render, press, click, type, screen } from "reakit-test-utils"; | ||
import AccessibleCombobox from ".."; | ||
|
||
test("open combobox popover on click", () => { | ||
render(<AccessibleCombobox />); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
}); | ||
|
||
test("open combobox popover on arrow down", () => { | ||
render(<AccessibleCombobox />); | ||
press.Tab(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
}); | ||
|
||
test("open combobox popover on arrow up", () => { | ||
render(<AccessibleCombobox />); | ||
press.Tab(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowUp(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
expect(screen.getByText("Banana")).not.toHaveFocus(); | ||
}); | ||
|
||
test("open combobox popover by typing on the combobox", () => { | ||
render(<AccessibleCombobox />); | ||
press.Tab(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
type("a"); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
}); | ||
|
||
test("do not open combobox popover on arrow right/left", () => { | ||
render(<AccessibleCombobox />); | ||
press.Tab(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowLeft(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowRight(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
}); | ||
|
||
test("do not open combobox popover on backspace on empty input", () => { | ||
render(<AccessibleCombobox />); | ||
press.Tab(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
type("\b"); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
}); | ||
|
||
test("close combobox popover by clicking outside", () => { | ||
const { baseElement } = render(<AccessibleCombobox />); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
click(baseElement); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
}); | ||
|
||
test("close combobox popover by tabbing out", () => { | ||
render( | ||
<> | ||
<AccessibleCombobox /> | ||
<button>button</button> | ||
</> | ||
); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.ArrowDown(); | ||
press.Tab(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
expect(screen.getByText("button")).toHaveFocus(); | ||
}); | ||
|
||
test("close combobox popover by pressing esc", () => { | ||
render(<AccessibleCombobox />); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
}); | ||
|
||
test("open combobox popover after pressing esc", () => { | ||
render(<AccessibleCombobox />); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowUp(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
type("a"); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
type("\b"); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
}); | ||
|
||
test("open combobox popover after pressing esc twice", () => { | ||
render(<AccessibleCombobox />); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
press.Escape(); | ||
press.Escape(); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
}); | ||
|
||
test("move through combobox options with keyboard", () => { | ||
render(<AccessibleCombobox />); | ||
click(screen.getByLabelText("Fruit")); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByText("Apple")).toHaveFocus(); | ||
press.ArrowDown(); | ||
expect(screen.getByText("Orange")).toHaveFocus(); | ||
press.ArrowDown(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
press.ArrowDown(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
expect(screen.getByText("Orange")).not.toHaveFocus(); | ||
expect(screen.getByText("Banana")).not.toHaveFocus(); | ||
press.ArrowUp(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
press.ArrowUp(); | ||
expect(screen.getByText("Orange")).toHaveFocus(); | ||
press.ArrowUp(); | ||
expect(screen.getByText("Apple")).toHaveFocus(); | ||
press.ArrowUp(); | ||
expect(screen.getByLabelText("Fruit")).toHaveFocus(); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
expect(screen.getByText("Orange")).not.toHaveFocus(); | ||
expect(screen.getByText("Banana")).not.toHaveFocus(); | ||
press.ArrowUp(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
press.ArrowRight(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
press.ArrowLeft(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
press.Home(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
press.End(); | ||
expect(screen.getByText("Banana")).toHaveFocus(); | ||
}); | ||
|
||
test("select combobox option by clicking on it", () => { | ||
render(<AccessibleCombobox />); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue(""); | ||
click(screen.getByText("Orange")); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue("Orange"); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
type("\b\b\b\b\b\ba"); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue("a"); | ||
click(screen.getByText("Apple")); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue("Apple"); | ||
}); | ||
|
||
test("select combobox option by pressing enter on it", () => { | ||
render(<AccessibleCombobox />); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue(""); | ||
press.ArrowUp(); | ||
press.Enter(); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue("Banana"); | ||
expect(screen.getByLabelText("Fruits")).not.toBeVisible(); | ||
type("\b\b\b\b\b\ba"); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue("a"); | ||
press.ArrowDown(); | ||
press.Enter(); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue("Apple"); | ||
}); | ||
|
||
test("do not select combobox option by pressing space on it", () => { | ||
render(<AccessibleCombobox />); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue(""); | ||
press.ArrowDown(); | ||
press.Space(); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue(""); | ||
expect(screen.getByLabelText("Fruits")).toBeVisible(); | ||
}); | ||
|
||
test("unselect combobox option when typing on the combobox", () => { | ||
render(<AccessibleCombobox />); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByLabelText("Fruit")).toHaveValue(""); | ||
press.ArrowDown(); | ||
expect(screen.getByText("Apple")).toHaveFocus(); | ||
type("a"); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
press.ArrowDown(); | ||
expect(screen.getByText("Apple")).toHaveFocus(); | ||
}); | ||
|
||
test("clicking on combobox input unselects combobox option", () => { | ||
render(<AccessibleCombobox />); | ||
click(screen.getByLabelText("Fruit")); | ||
press.ArrowDown(); | ||
expect(screen.getByText("Apple")).toHaveFocus(); | ||
click(screen.getByLabelText("Fruit")); | ||
expect(screen.getByText("Apple")).not.toHaveFocus(); | ||
}); |
23 changes: 23 additions & 0 deletions
23
packages/reakit/src/Combobox/__examples__/AccessibleComboboxContext/index.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,23 @@ | ||
import * as React from "react"; | ||
import { | ||
unstable_useComboboxState as useComboboxState, | ||
unstable_Combobox as Combobox, | ||
unstable_ComboboxPopover as ComboboxPopover, | ||
unstable_ComboboxOption as ComboboxOption, | ||
} from "reakit/Combobox"; | ||
|
||
import "./style.css"; | ||
|
||
export default function AccessibleComboboxContext() { | ||
const combobox = useComboboxState({ gutter: 8 }); | ||
return ( | ||
<> | ||
<Combobox {...combobox} aria-label="Fruit" /> | ||
<ComboboxPopover {...combobox} aria-label="Fruits"> | ||
<ComboboxOption value="Apple" /> | ||
<ComboboxOption value="Orange" /> | ||
<ComboboxOption value="Banana" /> | ||
</ComboboxPopover> | ||
</> | ||
); | ||
} |
Oops, something went wrong.