Skip to content

Feature: Shopping cart slide-out drawer #162

Description

@Daksh7785

Feature: Shopping cart slide-out drawer

Type: Feature / UX
Track: Frontend (React)
Priority: High
Difficulty: Intermediate

Problem statement

Currently, clicking Add to Cart only updates the cart counter in the Navbar. Users have no quick way to review the contents of their cart without navigating to a separate page, creating unnecessary friction during the shopping experience.

A slide-out cart drawer provides a faster and more intuitive shopping flow by allowing users to review, modify, and proceed to checkout without leaving the current page.

Description

Implement a slide-out Cart Drawer that opens from the right side of the screen when the user clicks the cart icon in the Navbar.

The drawer should display:

  • Book thumbnail

  • Book title

  • Price

  • Quantity controls

  • Remove item button

At the bottom of the drawer, display a dynamically calculated subtotal and a prominent Proceed to Checkout button.

The drawer should be dismissible via:

  • Backdrop click

  • Close (X) button

  • Escape key (recommended for accessibility)

Important: Keep this Pull Request focused solely on implementing the Cart Drawer UI and interactions. Avoid implementing payment processing or backend checkout functionality.

Objective

Create a responsive, accessible, and reusable slide-out cart drawer that allows users to manage their cart without leaving the current page.

Scope

The implementation should include:

  • Slide-out drawer

  • Cart item list

  • Quantity controls

  • Remove functionality

  • Dynamic subtotal

  • Checkout button

  • Backdrop overlay

  • Close interactions

  • Responsive design

  • Accessibility improvements

Functional requirements

Open drawer

Clicking the cart icon in the Navbar should:

  • Open the drawer

  • Display the current cart contents

  • Prevent background scrolling while open

Cart item display

Each cart item should show:

  • Book cover thumbnail

  • Book title

  • Price

  • Quantity

  • Quantity increase button

  • Quantity decrease button

  • Remove item button

Example:

--------------------------------

Cart


[IMG] Atomic Habits

$14.99

[-] 2 [+]

Remove


[IMG] Deep Work

$18.50

[-] 1 [+]

Remove


Quantity controls

Users should be able to:

  • Increase quantity

  • Decrease quantity

  • Remove items completely

Behavior:

  • Quantity cannot go below 1

  • Removing deletes the item from the cart

  • Navbar cart counter updates immediately

  • Subtotal updates automatically

Subtotal

Display:

Subtotal

$48.48

The subtotal should update whenever:

  • Items are added

  • Items are removed

  • Quantities change

Checkout button

Display a primary action button:

Proceed to Checkout

Clicking the button should navigate to:

/checkout

Empty cart state

When the cart is empty:

🛍️

Your cart is empty

Browse our collection and add your favorite books.

[ Start Shopping ]

Hide subtotal and checkout controls when the cart is empty.

Technical requirements

  • Use React functional components.

  • Reuse existing cart state.

  • Keep the drawer reusable.

  • Support smooth animations.

  • Maintain accessibility best practices.

Required file changes

Existing files to modify

File Folder Purpose
Navbar.jsx bookshelf-frontend/src/components/ Open/close drawer
Navbar.css bookshelf-frontend/src/components/ Cart icon interaction

Project structure impact

bookshelf-frontend/
└── src/
    ├── components/
    │   ├── Navbar.jsx
    │   ├── CartDrawer.jsx
    │   └── CartDrawer.css
    └── ...

Minimal architectural impact.

Implementation details

Drawer animation

Behavior:

Closed

Open

    ------------------

    Cart

    Items

    Subtotal

    Checkout

    ------------------

Use CSS transitions for:

  • Slide-in

  • Slide-out

  • Backdrop fade

State management

Suggested state:

const [isCartOpen, setIsCartOpen] = useState(false);

The Navbar controls opening.

The CartDrawer receives:

<CartDrawer
isOpen={isCartOpen}
onClose={handleClose}
/>

Backdrop

When open:

  • Display a semi-transparent overlay.

  • Clicking the backdrop closes the drawer.

Accessibility

Support:

  • Escape key to close

  • Focus trap inside the drawer (recommended)

  • aria-label on close button

  • role="dialog"

  • aria-modal="true"

Components affected

Frontend

  • Navbar

  • Cart state

  • CartDrawer

  • Checkout navigation

Dependencies

None required.

Reuse:

  • Existing cart context/state

  • Existing routing

  • Existing book data

Edge cases

  • Empty cart

  • Single item

  • Large quantities

  • Long book titles

  • Rapid quantity updates

  • Removing the last item

  • Drawer already open

  • Mobile screen sizes

Acceptance criteria

  • Clicking the Navbar cart icon opens the drawer.

  • Drawer slides in smoothly.

  • Cart items display correctly.

  • Quantity controls work.

  • Remove item works.

  • Subtotal updates dynamically.

  • Checkout button navigates to /checkout.

  • Clicking outside closes the drawer.

  • Clicking the X button closes the drawer.

  • Empty cart state displays correctly.

  • Existing cart functionality remains unchanged.

Testing requirements

Manual testing

Open / close

  • Open the drawer.

  • Close with X.

  • Close with backdrop.

  • Close with Escape.

Quantity

  • Increase quantity.

  • Decrease quantity.

  • Verify subtotal updates.

Remove

  • Remove one item.

  • Remove all items.

  • Verify empty state appears.

Checkout

  • Click Proceed to Checkout.

  • Verify navigation.

Responsive

  • Test desktop.

  • Test tablet.

  • Test mobile.

Accessibility

  • Tab through controls.

  • Verify keyboard navigation.

  • Verify focus behavior.

Regression

  • Add to Cart continues working.

  • Navbar counter remains correct.

  • Existing navigation remains unchanged.

  • Existing tests continue to pass.

Breaking changes

No

The drawer extends the cart experience without changing existing cart behavior.

Performance impact

Minimal.

  • Lightweight conditional rendering

  • CSS-based animations

  • Reuse existing cart state

Security considerations

None.

The drawer only displays existing client-side cart data.

Benefits

  • Faster cart access.

  • Reduced navigation friction.

  • Improved shopping experience.

  • Better mobile usability.

  • Increased checkout conversion potential.

  • Reusable drawer infrastructure for future features.

Definition of done

  • CartDrawer component implemented.

  • Slide-out animation completed.

  • Cart items rendered.

  • Quantity controls implemented.

  • Remove functionality implemented.

  • Dynamic subtotal implemented.

  • Checkout navigation implemented.

  • Backdrop close implemented.

  • X button close implemented.

  • Responsive styling completed.

  • Manual testing completed.

  • Existing functionality preserved.

  • Code follows project standards.

Suggested branch name

feature/cart-slideout-drawer

Labels

feature
frontend
react
cart
drawer
checkout
ui
ux
accessibility
intermediate

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions