Overview
At Urban Company, we offer a wide range of services organized into a hierarchical category structure. To enhance user experience and simplify navigation, we need a component that can display these categories in an expandable and collapsible tree view. This problem focuses on building a foundational UI component for presenting hierarchical data effectively.
What you need to do / Task
Your task is to implement a React component, CategoryTreeView, that renders a list of service categories and their subcategories in an interactive tree structure. The component should allow users to expand and collapse parent categories to reveal or hide their children.
- Render Categories: Display the name of each category.
- Hierarchical Display: Visually indent subcategories to indicate their nested level.
- Expand/Collapse Functionality: Implement controls (e.g., an arrow icon) that, when clicked, toggle the visibility of a parent category's children.
- Initial State: All parent categories should be collapsed by default when the component first renders.
UI/UX expectations
- Each category item should display its
name clearly.
- Parent categories (those with children) must have a visual indicator (e.g., a right-pointing triangle
▶ when collapsed, and a down-pointing triangle ▼ when expanded) next to their name.
- Clicking on this indicator or the parent category's name should toggle its expanded/collapsed state.
- Child categories must be indented relative to their parent to visually represent the hierarchy.
Acceptance criteria
- The component renders the provided hierarchical category data correctly.
- All parent categories are initially collapsed on load.
- Clicking the expand/collapse indicator (or category name) of a parent category toggles the visibility of its direct children.
- Subcategories are visibly indented according to their depth in the hierarchy.
- The UI remains responsive and free of console errors during interactions.
- The component correctly handles categories with no children (leaf nodes) without showing an expand/collapse indicator.