Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion a11y/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="ko">

<head>
<meta charset="UTF-8" />
Expand Down
8 changes: 4 additions & 4 deletions a11y/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import FlightBooking from "./components/FlightBooking";
function App() {
return (
<div className="app">
<div className="app-main">
<div className="flight-booking-container">
<main className="app-main">
<section className="flight-booking-container">
<FlightBooking />
</div>
</div>
</section>
</main>
</div>
);
}
Expand Down
17 changes: 17 additions & 0 deletions a11y/src/components/FlightBooking.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,20 @@
border-radius: 4px;
cursor: pointer;
}

.counter button:disabled {
opacity: 0.5;
cursor: not-allowed;
}

.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
68 changes: 51 additions & 17 deletions a11y/src/components/FlightBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,66 @@ const MAX_PASSENGERS = 3;

const FlightBooking = () => {
const [adultCount, setAdultCount] = useState(1);
const [announcement, setAnnouncement] = useState("");

const incrementCount = () => {
setAdultCount((prev) => Math.min(MAX_PASSENGERS, prev + 1));
const newCount = Math.min(MAX_PASSENGERS, adultCount + 1);
setAdultCount(newCount);

if (newCount === MAX_PASSENGERS) {
setAnnouncement("최대 승객 수에 도달했습니다. 성인 승객 3명");
} else {
setAnnouncement(`성인 승객 ${newCount}명`);
}
};

const decrementCount = () => {
setAdultCount((prev) => Math.max(1, prev - 1));
const newCount = Math.max(1, adultCount - 1);
setAdultCount(newCount);

if (newCount === 1) {
setAnnouncement("최소 승객 수에 도달했습니다. 성인 승객 1명");
} else {
setAnnouncement(`성인 승객 ${newCount}명`);
}
};

return (
<div className="flight-booking">
<h2 className="heading-2-text">항공권 예매</h2>
<div className="passenger-count">
<span className="body-text">성인</span>
<div className="counter">
<button className="button-text" onClick={decrementCount}>
-
</button>
<span>{adultCount}</span>
<button className="button-text" onClick={incrementCount}>
+
</button>
</div>
<article className="flight-booking">
<header>
<h1 className="heading-2-text">항공권 예매</h1>
</header>
<form>
<fieldset className="passenger-count">
<legend className="body-text">성인</legend>
<div className="counter">
<button
type="button"
className="button-text"
onClick={decrementCount}
aria-label="성인 승객 수 감소"
disabled={adultCount <= 1}
>
-
</button>
<span aria-live="polite" aria-label={`현재 성인 승객 ${adultCount}명`}>{adultCount}</span>
<button
type="button"
className="button-text"
onClick={incrementCount}
aria-label="성인 승객 수 증가"
disabled={adultCount >= MAX_PASSENGERS}
>
+
</button>
</div>
</fieldset>
<button type="submit" className="search-button">항공편 검색</button>
</form>
<div aria-live="assertive" aria-atomic="true" role="status" className="sr-only">
{announcement}
</div>
<button className="search-button">항공편 검색</button>
</div>
</article>
);
};

Expand Down