Overview
In travel booking platforms like Ixigo, selecting the number and type of passengers is a crucial step. This selection often happens within a dedicated modal dialog to provide a focused user experience without cluttering the main booking form. For this problem, you will build a robust and user-friendly passenger selection modal.
What you need to do / Task
Your primary task is to implement a PassengerSelectorModal component and integrate it into App.tsx.
- Modal Trigger: Render a button on the main
App component that, when clicked, opens the PassengerSelectorModal.
- Passenger Type Counters: Inside the modal, display three distinct sections for:
- Adults (12+ years)
- Children (2-12 years)
- Infants (under 2 years, lap-held)
Each section must have:
- A label (e.g., "Adults")
- A current count display
- Two buttons: one to decrement the count (
-) and one to increment the count (+).
- Apply Button: Implement an "Apply" button within the modal. Clicking this button should save the currently selected passenger counts and close the modal.
- Cancel/Close Functionality:
- Implement a "Cancel" button that discards any changes and closes the modal.
- Implement a close button (e.g., an 'X' icon) in the modal header that also discards changes and closes the modal.
- Display Selected Passengers: After applying changes, the main
App component should display the total selected passengers and their breakdown (e.g., "3 Passengers (2 Adults, 1 Child, 0 Infants)").
UI/UX expectations
- Layout: The modal should appear centered on the screen, overlaying the main content. The main content should be visually subdued (e.g., dimmed) when the modal is open.
- Controls: Increment/decrement buttons should be clearly visible and functional. The current count should be displayed between them.
- Accessibility:
- The modal should be keyboard navigable (e.g.,
Tab key to move between controls, Esc key to close the modal).
- Appropriate ARIA attributes (e.g.,
role="dialog", aria-modal="true", aria-labelledby) should be used for the modal itself and its interactive elements.
- Focus should be trapped within the modal when it's open.
- Visual Feedback: Buttons should provide hover/focus states. Disabled buttons (due to constraints) should be visually distinct.
Acceptance criteria
- The "Select Passengers" button correctly opens the modal.
- The modal displays sections for Adults, Children, and Infants with +/- buttons and current counts.
- Incrementing/decrementing counts works correctly for each passenger type.
- Constraints are correctly applied:
- Adults count is always >= 1.
- Total passengers (Adults + Children) <= 9.
- Infants count <= Adults count.
- The "Apply" button saves the selection, closes the modal, and updates the display in
App.tsx.
- The "Cancel" button closes the modal without saving changes.
- The 'X' close button closes the modal without saving changes.
- Pressing
Esc key closes the modal without saving changes.
- Modal is keyboard navigable and traps focus.
- Modal has appropriate ARIA attributes.