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
11 changes: 11 additions & 0 deletions a11y/src/components/FlightBooking.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,14 @@
border-radius: 4px;
cursor: pointer;
}

.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
border: 0;
}
42 changes: 36 additions & 6 deletions a11y/src/components/FlightBooking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,65 @@ import { useState } from "react";
import "./FlightBooking.css";

const MAX_PASSENGERS = 3;
const MIN_PASSENGERS = 1;

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

const incrementCount = () => {
setAdultCount((prev) => Math.min(MAX_PASSENGERS, prev + 1));
setAdultCount((prev) => {
if (prev < MAX_PASSENGERS) {
const newValue = prev + 1;
setAnnouncement(`성인 승객 증가 ${newValue}`);
return newValue;
} else {
setAnnouncement("최대 승객 수에 도달하였습니다.");
return prev;
}
});
};

const decrementCount = () => {
setAdultCount((prev) => Math.max(1, prev - 1));
setAdultCount((prev) => {
if (prev > MIN_PASSENGERS) {
const newValue = prev - 1;
setAnnouncement(`성인 승객 감소 ${newValue}`);
return newValue;
} else {
// 필요하다면 최소 안내도 추가 가능
setAnnouncement("최소 1명의 승객이 필요합니다.");
return prev;
}
});
};

return (
<div className="flight-booking">
<section 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 className="button-text" onClick={decrementCount} aria-label="성인 승객 감소" aria-live="polite">
-
</button>
<span>{adultCount}</span>
<button className="button-text" onClick={incrementCount}>
<button className="button-text" onClick={incrementCount} aria-label="성인 승객 증가" aria-live="polite">
+
</button>
</div>
</div>
<button className="search-button">항공편 검색</button>
</div>

{/* 스크린리더 전용 안내 영역 */}
<div
aria-live="assertive"
aria-atomic="true"
className="visually-hidden"
>
{announcement}
</div>
</section>
);
};

Expand Down