Skip to content

Commit 986085f

Browse files
committed
👌 IMPROVE: a11y example with Styled Components
1 parent a28c09e commit 986085f

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎examples/05-a11y-input/README.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This example includes a WordPress Gutenberg plugin called `a11y-input` which cre
1616

1717
- [Run `npx create-guten-block a11y-input` →](https://github.com/ahmadawais/create-guten-block#getting-started)
1818
- Write code in `a11y-input/src/block/block.js`.
19+
- OPTIONAL: Installed styled-components `npm i -D styled-components`
20+
1921

2022
_That's about it._
2123
>🌟 Star for updates or to appreciate [create-guten-block →](https://github.com/ahmadawais/create-guten-block)
@@ -100,9 +102,9 @@ There are a number of tools we can use to assist in the creation of accessible w
100102
By far the easiest and also one of the most important checks is to test if your entire website can be reached and used with the keyboard alone. Do this by:
101103

102104
1. Plugging out your mouse.
103-
1. Using `Tab` and `Shift+Tab` to browse.
104-
1. Using `Enter` to activate elements.
105-
1. Where required, using your keyboard arrow keys to interact with some elements, such as menus and dropdowns.
105+
2. Using `Tab` and `Shift+Tab` to browse.
106+
3. Using `Enter` to activate elements.
107+
4. Where required, using your keyboard arrow keys to interact with some elements, such as menus and dropdowns.
106108

107109
### Development assistance
108110

‎examples/05-a11y-input/dist/blocks.build.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/05-a11y-input/src/block/block.js‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@
66
*/
77

88
// Import CSS.
9+
import styled from 'styled-components';
910
import './editor.scss';
1011
import './style.scss';
1112

1213
const { __ } = wp.i18n; // Import __() from wp.i18n
1314
const { registerBlockType } = wp.blocks; // Import registerBlockType() from wp.blocks
1415

1516
const labelText = 'NAME (Accessible Text Input)';
16-
const inputValue = 'Ahmad Awais (Accessible Input Value)';
17+
18+
const Input = styled.input`
19+
display: table;
20+
width: 50%;
21+
border: 1px solid !important;
22+
box-shadow: 0.1rem 0.1rem 0 !important;
23+
padding: 1rem !important;
24+
`;
1725

1826
/**
1927
* Register: aa Gutenberg Block.
@@ -46,7 +54,9 @@ registerBlockType( 'cgb/block-a11y-input', {
4654
*/
4755
edit: function() {
4856
// Creates a <p class='wp-block-cgb-block-a11y-input'></p>.
49-
return <input type="text" aria-label={ labelText } aria-required="true" value={ inputValue } name="name" />;
57+
return (
58+
<Input type="text" placeholder="Enter something…" aria-label={ labelText } aria-required="true" name="name" />
59+
);
5060
},
5161

5262
/**
@@ -60,6 +70,8 @@ registerBlockType( 'cgb/block-a11y-input', {
6070
*/
6171
save: function() {
6272
// Creates a <p class='wp-block-cgb-block-a11y-input'></p>.
63-
return <input type="text" aria-label={ labelText } aria-required="true" value={ inputValue } name="name" />;
73+
return (
74+
<Input type="text" placeholder="Enter something…" aria-label={ labelText } aria-required="true" name="name" />
75+
);
6476
},
6577
} );

0 commit comments

Comments
 (0)