Wish list

Wish List/Save for Later Forms #

Description: An accessible Wish List or Save for Later form allows the users to save products they’re interested in for future viewing

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Accessible Wish List Form</title>
    <style>
        .hidden {
            display: none;
        }
        .focusable:focus {
            outline: 3px solid #FFBF00;
        }
        .wishlist-button {
            padding: 10px;
            background-color: #007BFF;
            color: #FFF;
            border: none;
            cursor: pointer;
        }
        .wishlist-button[aria-pressed="true"] {
            background-color: #FF5733;
        }
    </style>
    <script>
        function toggleWishList(button) {
            const isSaved = button.getAttribute('aria-pressed') === 'true';
            const statusMessage = document.getElementById('status-message');
            if (isSaved) {
                // If item is already saved, remove it from the Wish List
                button.setAttribute('aria-pressed', 'false');
                button.textContent = "Save to Wish List";
                statusMessage.textContent = "Item removed from Wish List.";
            } else {
                // If item is not saved, add it to the Wish List
                button.setAttribute('aria-pressed', 'true');
                button.textContent = "Remove from Wish List";
                statusMessage.textContent = "Item saved to Wish List.";
            }
            statusMessage.classList.remove('hidden');
            statusMessage.setAttribute('aria-live', 'polite');
        }
    </script>
</head>
<body>
    <h1>Product</h1>
    <p>Product Name: Cozy Blanket</p>
    <p>Price: $29.99</p>
    <!-- Wish List Button -->
    <button
        class="wishlist-button focusable"
        aria-pressed="false"
        aria-label="Save to Wish List"
        onclick="toggleWishList(this)">
        Save to Wish List
    </button>
    <!-- Status Message -->
    <div id="status-message" role="status" aria-live="polite" class="hidden"></div>
</body>
</html>

Explanation #

  1. Clear Labels and Descriptive Buttons:
    • The button has an aria-label attribute for accessibility, so screen readers announce “Save to Wish List” when focused. This ensures clarity for users who cannot see the button.
  2. Accessible Feedback Using Live Regions:
    • A polite live region (aria-live="polite") is used for the feedback message in #status-message, notifying users whenever an item is added or removed from the Wish List without interrupting their activity.
  3. Toggle Button with ARIA:
    • The button uses aria-pressed to indicate its state. When the item is saved, aria-pressed="true" shows that the item is in the Wish List; when it’s removed, aria-pressed="false" provides feedback that the item is no longer saved.
    • The button text changes between “Save to Wish List” and “Remove from Wish List” based on the state, providing visual feedback to all users.
  4. Keyboard Navigation:
    • The button is fully keyboard accessible, and the .focusable class provides a visible outline when the button is focused, making it easy for keyboard users to track their location within the form.

Key Takeaways #

  • Use Clear Labels and Descriptive Button Text: Buttons should have clear text or aria-label attributes that describe their purpose. For icons-only buttons, use aria-label to ensure screen reader users know the button’s function.
  • Provide Accessible Feedback for Actions: Use live regions to announce feedback when an item is added or removed from the Wish List. Use polite live regions (aria-live="polite") to provide non-disruptive feedback, helping users confirm actions.
  • Implement ARIA Attributes for Toggle Buttons: Use aria-pressed="true" and aria-pressed="false" for toggling buttons like “Save to Wish List,” allowing screen readers to announce the item’s saved status.
  • Ensure Keyboard Accessibility: The Wish List button should be accessible by keyboard, with a logical tab order and clear focus indicators. Avoid unexpected focus shifts to keep users oriented within the form.
  • Provide Accessible Removal Options: For removing items from the Wish List, provide a clear label (e.g., “Remove from Wish List”) and confirmation feedback to avoid accidental actions.

What are your feelings

Updated on March 6, 2025