Skip to content

Commit 3c5a508

Browse files
committed
improved accessibility by adding search semantic element, hiding decorative icon and adding a label for screen readers
1 parent 915a031 commit 3c5a508

3 files changed

Lines changed: 54 additions & 34 deletions

File tree

src/SearchBar.jsx

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,48 @@ function SearchBar () {
2424
searchBarClasses.splice(indexOfError - 1, 1)
2525
}
2626
return (
27-
<form
28-
onSubmit={e => {
29-
submitSearch(e)
30-
}}
31-
>
32-
<div
33-
className={`search-bar br-medium` + ' ' + searchBarClasses.join(' ')}
27+
<search>
28+
<form
29+
onSubmit={e => {
30+
submitSearch(e)
31+
}}
3432
>
35-
<div className='icon'>
36-
<svg height='24' width='25' xmlns='http://www.w3.org/2000/svg'>
37-
<path
38-
d='M10.609 0c5.85 0 10.608 4.746 10.608 10.58 0 2.609-.952 5-2.527 6.847l5.112 5.087a.87.87 0 01-1.227 1.233l-5.118-5.093a10.58 10.58 0 01-6.848 2.505C4.759 21.16 0 16.413 0 10.58 0 4.747 4.76 0 10.609 0zm0 1.74c-4.891 0-8.87 3.965-8.87 8.84 0 4.874 3.979 8.84 8.87 8.84a8.855 8.855 0 006.213-2.537l.04-.047a.881.881 0 01.058-.053 8.786 8.786 0 002.558-6.203c0-4.875-3.979-8.84-8.87-8.84z'
39-
fill='#0079ff'
40-
/>
41-
</svg>
33+
<div
34+
className={`search-bar br-medium` + ' ' + searchBarClasses.join(' ')}
35+
>
36+
<div className='icon' aria-hidden='true'>
37+
<svg height='24' width='25' xmlns='http://www.w3.org/2000/svg'>
38+
<path
39+
d='M10.609 0c5.85 0 10.608 4.746 10.608 10.58 0 2.609-.952 5-2.527 6.847l5.112 5.087a.87.87 0 01-1.227 1.233l-5.118-5.093a10.58 10.58 0 01-6.848 2.505C4.759 21.16 0 16.413 0 10.58 0 4.747 4.76 0 10.609 0zm0 1.74c-4.891 0-8.87 3.965-8.87 8.84 0 4.874 3.979 8.84 8.87 8.84a8.855 8.855 0 006.213-2.537l.04-.047a.881.881 0 01.058-.053 8.786 8.786 0 002.558-6.203c0-4.875-3.979-8.84-8.87-8.84z'
40+
fill='#0079ff'
41+
/>
42+
</svg>
43+
</div>
44+
<label htmlFor='username' className='sr-only'>
45+
Enter GitHub username to find
46+
</label>
47+
<input
48+
id='username'
49+
type='text'
50+
value={searchedUser}
51+
placeholder='Search GitHub username...'
52+
onChange={e => setSearchedUser(e.target.value)}
53+
onInput={e => {
54+
setSearchedUser(e.target.value)
55+
getUserSuggestions(e.target.value)
56+
}}
57+
onBlur={() => setStartId(0)}
58+
ref={inputValueRef}
59+
/>
60+
{isError && <div className='info'>{errorMessage}</div>}
61+
{isIssue && <div className='info'>{errorMessage}</div>}
62+
<button type='submit' className='button search-button'>
63+
Search
64+
</button>
65+
<SuggestionList suggestions={suggestionList}></SuggestionList>
4266
</div>
43-
<input
44-
type='text'
45-
value={searchedUser}
46-
placeholder='Search GitHub username...'
47-
onChange={e => setSearchedUser(e.target.value)}
48-
onInput={e => {
49-
setSearchedUser(e.target.value)
50-
getUserSuggestions(e.target.value)
51-
}}
52-
onBlur={() => setStartId(0)}
53-
ref={inputValueRef}
54-
/>
55-
{isError && <div className='info'>{errorMessage}</div>}
56-
{isIssue && <div className='info'>{errorMessage}</div>}
57-
<button type='submit' className='button search-button'>
58-
Search
59-
</button>
60-
<SuggestionList suggestions={suggestionList}></SuggestionList>
61-
</div>
62-
</form>
67+
</form>
68+
</search>
6369
)
6470
}
6571
export default SearchBar

src/sass/utilities/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
@forward './letter-spacing';
1111
@forward './main-title';
1212
@forward './spacing';
13+
@forward './sr-only';
1314
@forward './text-center';
1415
@forward './uppercase';

src/sass/utilities/_sr-only.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@use '../abstracts/' as *;
2+
3+
.sr-only {
4+
position: absolute;
5+
width: 1px;
6+
height: 1px;
7+
padding: 0;
8+
margin: -1px;
9+
overflow: hidden;
10+
clip: rect(0, 0, 0, 0);
11+
white-space: nowrap;
12+
border: 0;
13+
}

0 commit comments

Comments
 (0)