-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
/ts | ||
/utils | ||
/system | ||
/VisuallyHidden | ||
/Tooltip | ||
/Toolbar | ||
/Tabbable | ||
|
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,53 @@ | ||
--- | ||
path: /docs/visually-hidden | ||
--- | ||
|
||
# VisuallyHidden | ||
|
||
`VisuallyHidden` is a common techinique used in web accessibility to hide content from the visual client, but keep it readable for screen readers. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm install reakit | ||
``` | ||
|
||
Learn more in [Get started](/docs/get-started). | ||
|
||
## Usage | ||
|
||
<!-- eslint-disable import/no-unresolved --> | ||
|
||
```jsx | ||
import { Button } from "reakit/Button"; | ||
import { VisuallyHidden } from "reakit/VisuallyHidden"; | ||
import UniversalAccess from "./UniversalAccess"; | ||
|
||
function Example() { | ||
return ( | ||
<Button> | ||
<VisuallyHidden>Universal Access</VisuallyHidden> <UniversalAccess /> | ||
</Button> | ||
); | ||
} | ||
``` | ||
|
||
## Accessibility | ||
|
||
- `VisuallyHidden` has all the styles necessary to hide it from visual clients, but keep it for screen readers. | ||
|
||
Learn more in [Accessibility](/docs/accessibility). | ||
|
||
## Composition | ||
|
||
- `Separator` uses [Box](/docs/box). | ||
|
||
Learn more in [Composition](/docs/composition#props-hooks). | ||
|
||
## Props | ||
|
||
<!-- Automatically generated --> | ||
|
||
### `VisuallyHidden` | ||
|
||
No props to show |
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,47 @@ | ||
import { unstable_createComponent } from "../utils/createComponent"; | ||
import { mergeProps } from "../utils/mergeProps"; | ||
import { unstable_useProps } from "../system/useProps"; | ||
import { BoxOptions, BoxProps, useBox } from "../Box/Box"; | ||
import { Keys } from "../__utils/types"; | ||
import { unstable_useOptions } from "../system"; | ||
|
||
export type VisuallyHiddenOptions = BoxOptions; | ||
|
||
export type VisuallyHiddenProps = BoxProps; | ||
|
||
export function useVisuallyHidden( | ||
options: VisuallyHiddenOptions = {}, | ||
htmlProps: VisuallyHiddenProps = {} | ||
) { | ||
options = unstable_useOptions("VisuallyHidden", options, htmlProps); | ||
|
||
htmlProps = mergeProps( | ||
{ | ||
style: { | ||
border: 0, | ||
clip: "rect(0 0 0 0)", | ||
height: "1px", | ||
margin: "-1px", | ||
overflow: "hidden", | ||
padding: 0, | ||
position: "absolute", | ||
whiteSpace: "nowrap", | ||
width: "1px" | ||
} | ||
} as typeof htmlProps, | ||
htmlProps | ||
); | ||
|
||
htmlProps = unstable_useProps("VisuallyHidden", options, htmlProps); | ||
htmlProps = useBox(options, htmlProps); | ||
return htmlProps; | ||
} | ||
|
||
const keys: Keys<VisuallyHiddenOptions> = [...useBox.__keys]; | ||
|
||
useVisuallyHidden.__keys = keys; | ||
|
||
export const VisuallyHidden = unstable_createComponent({ | ||
as: "div", | ||
useHook: useVisuallyHidden | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/reakit/src/VisuallyHidden/__tests__/VisuallyHidden-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,8 @@ | ||
import * as React from "react"; | ||
import { render } from "react-testing-library"; | ||
import { VisuallyHidden } from "../VisuallyHidden"; | ||
|
||
test("render", () => { | ||
const { baseElement } = render(<VisuallyHidden />); | ||
expect(baseElement).toMatchInlineSnapshot(); | ||
}); |
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 @@ | ||
export * from "./VisuallyHidden"; |
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