# Icon Button Pattern

## Objective

Keep icon-only controls compact without making them guesswork.

A rule set for controls that show an icon and no label, covering naming, hit area, tooltips, and interaction states.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. List every icon-only control in the app and give each one a written accessible name that describes the action, not the picture. Close dialog, not cross.
2. Restrict icon-only treatment to actions whose meaning is genuinely conventional or whose context makes them obvious — a close, a menu, an overflow, a sort. Anything else gets a label.
3. Size the icon and the hit area independently, so a sixteen pixel icon still sits inside a target large enough for a thumb, with the extra area coming from padding rather than from a larger glyph.
4. Define hover, focus, active, disabled, and selected for every icon button, and make the selected state distinguishable from hover so a toggled control does not read as merely pointed at.
5. Do not rely on a tooltip to carry the meaning. Tooltips never appear on touch, are slow on keyboard, and vanish for anyone using magnification — treat them as a reminder for people who already know.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- An icon button with no accessible name is announced as an unlabelled button, which makes the control unusable by anyone not looking at the screen.
- Tooltips are unavailable on touch devices and delayed on keyboard focus, so any control whose only explanation is a tooltip is unlabelled for a large share of users.
- The visible icon and the clickable area are different measurements. Enlarging the glyph to reach a comfortable target makes the interface shout; enlarging the padding does not.
- Every interaction state must be defined explicitly, including the toggled-on state. A missing selected style leaves the user unable to tell whether the filter, the mute, or the pin is currently active.
- Adjacent icon buttons in a toolbar need enough separation that their hit areas do not overlap, or users will activate the neighbour.
- An icon whose meaning changes with state, such as play becoming pause, must change its accessible name at the same moment as its glyph.
- Overflow menus triggered by an icon must remain reachable by keyboard and must return focus to the trigger when they close.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Every icon-only control has an accessible name describing its action.
- [ ] No control depends on a tooltip to be understood.
- [ ] Hit areas meet the minimum touch target while the icons stay at their intended visual size.
- [ ] Hover, focus, active, disabled, and selected are each visually distinct.
- [ ] Toggled controls announce and display their current state.
- [ ] Adjacent icon buttons have non-overlapping hit areas.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
