Skip to content

Commit 0b9257d

Browse files
committed
improvement: a11y: add role="search" for search
1 parent 34845d4 commit 0b9257d

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

packages/frontend/src/components/SearchInput/index.tsx

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,39 @@ export default function SearchInput(props: Props) {
4141

4242
return (
4343
<>
44-
<input
45-
id={id}
46-
placeholder={tx('search')}
47-
aria-label={tx('search')}
48-
aria-description={tx('search_explain')}
49-
autoFocus
50-
onChange={onChange}
51-
value={value}
52-
className={styles.searchInput}
53-
data-no-drag-region
54-
ref={props.inputRef}
55-
spellCheck={false}
56-
// FYI there is also Ctrl + Shift + F to search in chat.
57-
aria-keyshortcuts='Control+F'
58-
/>
59-
{hasValue && (
60-
<SearchInputButton
61-
aria-label={tx('clear_search')}
62-
icon='cross'
63-
onClick={handleClear}
44+
<div
45+
role='search'
46+
// `aria-label={tx('search')}` is not required,
47+
// a "search" landmark is enough.
48+
// Note that `_explain` strings are generally verbose
49+
// and are more suitable for `aria-description`,
50+
// but here it's fine to use it as the label.
51+
// We must speecify the label, because we have multiple searches
52+
// in the app, another one being the attachments search.
53+
aria-label={tx('search_explain')}
54+
className={styles.inputAndClearButton}
55+
>
56+
<input
57+
id={id}
58+
placeholder={tx('search')}
59+
autoFocus
60+
onChange={onChange}
61+
value={value}
62+
className={styles.searchInput}
63+
data-no-drag-region
64+
ref={props.inputRef}
65+
spellCheck={false}
66+
// FYI there is also Ctrl + Shift + F to search in chat.
67+
aria-keyshortcuts='Control+F'
6468
/>
65-
)}
69+
{hasValue && (
70+
<SearchInputButton
71+
aria-label={tx('clear_search')}
72+
icon='cross'
73+
onClick={handleClear}
74+
/>
75+
)}
76+
</div>
6677
{!hasValue && (
6778
<SearchInputButton
6879
aria-label={tx('qrscan_title')}

packages/frontend/src/components/SearchInput/styles.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
$borderRadius: 10px;
22
$closeButtonSize: 30px;
33

4+
.inputAndClearButton {
5+
flex: 1;
6+
display: flex;
7+
align-items: center;
8+
}
9+
410
.searchInput {
511
background-color: var(--searchInputBackgroundColor);
612
border-radius: $borderRadius;

0 commit comments

Comments
 (0)