BEGINNER • HTML and CSS Basics
Sprint: improve component reusability #17
This lesson focuses on improve component reusability for a e-commerce product page interface. You will use: element.addEventListener('click', handler) | npm create vite@latest my-app | npm run build. The content is designed for practical frontend development.
Code Example
// Accessible component
<button
aria-label="Add to cart"
aria-pressed={isInCart}
onClick={handleClick}
>
Add to Cart
</button>
// Objective: improve component reusabilityCommands & References
- element.addEventListener('click', handler)
- npm create vite@latest my-app
- npm run build
Lab Steps
- Set up with: element.addEventListener('click', handler)
- Build or refactor the component for the scenario.
- Validate accessibility and performance.
- Propose one improvement for production.
Exercises
- Add one accessibility enhancement.
- Implement one performance optimization.
- Write one unit test for this component.