Skip to content

feat: add live character counter to InputField maxLength fields (Closes #1291) - #1373

Open
waterWang wants to merge 1 commit into
Fluxora-Org:mainfrom
waterWang:feature/inputfield-character-counter
Open

feat: add live character counter to InputField maxLength fields (Closes #1291)#1373
waterWang wants to merge 1 commit into
Fluxora-Org:mainfrom
waterWang:feature/inputfield-character-counter

Conversation

@waterWang

Copy link
Copy Markdown

Summary

Adds an opt-in live character counter (42/100 style) to InputField fields that declare a maxLength prop, implementing issue #1291.

Changes

src/components/InputField.tsx

  • Added maxLength prop to InputFieldProps — counter only renders when explicitly provided
  • Counter reads the child <input>'s current value to derive charCount in real time
  • Counter text is linked via aria-describedby on the input
  • Debounced aria-live="polite" announcement (600ms, via a visually-hidden .input-char-counter__announcer) so screen readers aren't overwhelmed on every keystroke
  • Forwards the maxLength to the underlying <input> element for native browser enforcement
  • Warning styling (danger color + bold text) when within 10% of the limit

src/components/CreateStreamModal.css

  • Added .input-char-counter, .input-char-counter__text, .input-char-counter--warning, and .input-char-counter__announcer styles

src/components/__tests__/InputField.characterCounter.test.tsx

  • 8 tests covering: no counter without maxLength, counter display, live update while typing, aria-describedby linkage, warning threshold, debounced announcement, and maxlength attribute forwarding

Testing

  • ✅ 8 new character counter tests pass
  • ✅ Existing InputField tests unaffected (2 pre-existing failures unrelated to this change — Property 11 has an undefined input variable, and the debounced validation test has a timer interaction issue)
  • ✅ WCAG 2.1 AA compliant (counter linked via aria-describedby, debounced aria-live="polite", warning not color-only — also bolds the text)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant