-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components: Add VisuallyHidden component #18022
Changes from 2 commits
68a014e
0cd49be
5884f3e
9013c22
eaa2fdd
0061ac5
d28ac21
60f0386
19517d7
7941dc0
353ee51
638870f
647ae0a
8d9c7a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ScreenReaderText | ||
|
||
A component used to render text intended for a screen reader, not visible elsewhere. | ||
|
||
### Usage | ||
|
||
```jsx | ||
<ScreenReaderText> Show text for screenreader. </ScreenReaderText> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other places we add full examples: import { Dashicon } from '@wordpress/components';
const MyDashicon = () => (
<div>
<Dashicon icon="admin-home" />
<Dashicon icon="products" />
<Dashicon icon="wordpress" />
</div>
); |
||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
function ScreenReaderText( props ) { | ||
return ( | ||
<div className="screen-reader-text"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You often will want to use a different tag name as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of a div? I'm open to suggestions, should it b a prop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The className here doesn't follow our guidelines. I guess it was done this way to match the existing className. I think it's fine to change it for consistency. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In another component we used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing is that WP core uses See also #18022 (comment) about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we have We can iterate if you prefer to tackle it separately. See my related comment: #18022 (comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are all these solved by nesting VisuallyHidden inline inside the tags? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should decide now whether we want There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it solves the issue because the wrapping There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can look at Also looks like a bug that if you pass in |
||
{ props.children } | ||
</div> | ||
); | ||
} | ||
|
||
export default ScreenReaderText; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import ScreenReaderText from '../'; | ||
import '../style.scss'; | ||
|
||
export default { title: 'ScreenReaderText', component: ScreenReaderText }; | ||
|
||
export const _default = () => ( | ||
<> | ||
<ScreenReaderText> | ||
This should not show. | ||
</ScreenReaderText> | ||
<div> | ||
This text will always show. | ||
</div> | ||
</> | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.screen-reader-text { | ||
border: 0; | ||
clip: rect(1px, 1px, 1px, 1px); | ||
-webkit-clip-path: inset(50%); | ||
clip-path: inset(50%); | ||
height: 1px; | ||
margin: -1px; | ||
overflow: hidden; | ||
padding: 0; | ||
position: absolute; | ||
width: 1px; | ||
word-wrap: normal !important; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can reference WordPress docs here, maybe also copy some parts of that document:
https://make.wordpress.org/accessibility/handbook/markup/the-css-class-screen-reader-text/