Skip to content

Commit 713f975

Browse files
authored
Merge pull request #47 from CBID2/improving-input
a11y: improving the search input field
2 parents c897d1b + ac1a719 commit 713f975

File tree

2 files changed

+69
-37
lines changed

2 files changed

+69
-37
lines changed

‎src/Search.css‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.search-form {
2+
display: flex;
3+
justify-content: center;
4+
margin: 1rem 0;
5+
}
6+
7+
.search-container {
8+
width: 100%;
9+
max-width: 400px;
10+
}
11+
12+
.search-label {
13+
display: block;
14+
font-size: 1rem;
15+
color: #333;
16+
}
17+
18+
.search-input {
19+
width: 100%;
20+
padding: 0.5rem;
21+
font-size: 1rem;
22+
border: 1px solid #ccc;
23+
border-radius: 4px;
24+
}
25+
26+
.search-input:focus {
27+
border-color: #007bff;
28+
outline: none;
29+
box-shadow: 0 0 3px rgba(0, 123, 255, 0.5);
30+
}

‎src/Search.jsx‎

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1-
import React from 'react'
2-
import { useGlobalContext } from './Context'
3-
1+
import React from "react";
2+
import { useGlobalContext } from "./Context";
43

54
const Search = () => {
6-
const { query, searchFn, showPopularNews, setReadingMode, readingMode } = useGlobalContext();
7-
return (
8-
<>
9-
<div
10-
style={{
11-
display: "flex",
12-
justifyContent: "center",
13-
}}>
14-
<button
15-
onClick={() => setReadingMode(!readingMode)}
16-
>
17-
{readingMode ? "Exit Reading Mode" : "Enter Reading Mode"}
18-
</button>
19-
</div>
20-
<h1 className="heading">
21-
<span className='subText'>T</span>ech
22-
<span className='subText'>P</span>ulse
23-
</h1>
24-
25-
{!showPopularNews &&
26-
<form>
27-
<div>
28-
<input type="text" placeholder="search here"
29-
value={query}
30-
onChange={(e) => searchFn(e.target.value)}
31-
/>
32-
</div>
33-
</form>
34-
}
35-
</>
36-
5+
const { query, searchFn, showPopularNews, setReadingMode, readingMode } =
6+
useGlobalContext();
7+
return (
8+
<>
9+
<div
10+
style={{
11+
display: "flex",
12+
justifyContent: "center",
13+
}}>
14+
<button onClick={() => setReadingMode(!readingMode)}>
15+
{readingMode ? "Exit Reading Mode" : "Enter Reading Mode"}
16+
</button>
17+
</div>
18+
<h1 className="heading">
19+
<span className="subText">T</span>ech
20+
<span className="subText">P</span>ulse
21+
</h1>
3722

38-
)
39-
}
23+
{!showPopularNews && (
24+
<form className="search-form">
25+
<div className="search-container">
26+
<label htmlFor="search-input" className="search-label">
27+
Search for articles:
28+
</label>
29+
<input
30+
id="search-input"
31+
type="text"
32+
placeholder="search here"
33+
value={query}
34+
onChange={(e) => searchFn(e.target.value)}
35+
/>
36+
</div>
37+
</form>
38+
)}
39+
</>
40+
);
41+
};
4042

41-
export default Search
43+
export default Search;

0 commit comments

Comments
 (0)