Patterns · Settings
Counted input
A single-line settings field whose character counter shows only while the field is focused and is hidden at rest — the shared CountedInput pattern for option/answer text.
Examples
Size
Max length
Status
Focus a field — the counter appears only while focused, hidden at rest
Sizes · small 24 · default 32 · large 40
States · no counter · disabled · readonly
<!-- Paste-and-run: save as .html and open in a browser. No build step.
<aha-counted-input> is the SAME shared custom element React and Vue consume — here in its
native form. Theming comes only from the --aha-* tokens in tokens.css. The character counter
is revealed only while the field is focused (SETTINGS-21/42) — click in to see it. -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ahaslides-product/ahaslides-design@master/lib/tokens.css">
<script type="module">
import 'https://cdn.jsdelivr.net/gh/ahaslides-product/ahaslides-design@master/lib/aha-counted-input.js'; // registers <aha-counted-input>
</script>
<!-- maxlength turns the focus-only counter on (shows current/max) -->
<aha-counted-input id="opt" maxlength="80" value="Paris" placeholder="Option text"></aha-counted-input>
<!-- size: small | default | large · status: error · disabled / readonly -->
<aha-counted-input size="large" maxlength="40" placeholder="Large"></aha-counted-input>
<aha-counted-input status="error" maxlength="80" value="Too long" placeholder="Answer"></aha-counted-input>
<script>
// Plain DOM — no framework. Read e.detail.value off the composed CustomEvent.
document.getElementById('opt').addEventListener('input', (e) => {
console.log('value:', e.detail.value);
});
</script>
import '@ahaslides-product/design/aha-counted-input'; // registers <aha-counted-input>
import { useRef, useEffect } from 'react';
// React 18 needs a thin wrapper; React 19 can use <aha-counted-input> directly.
// size: 'small' | 'default' | 'large' · the counter shows only on focus when maxLength is set.
function AhaCountedInput({ value, placeholder, maxLength, size, status, disabled, readOnly, onChange }) {
const ref = useRef();
useEffect(() => {
const el = ref.current;
el.value = value ?? '';
el.disabled = !!disabled;
const h = (e) => onChange?.(e.detail.value); // composed CustomEvent
el.addEventListener('input', h);
return () => el.removeEventListener('input', h);
});
return (
<aha-counted-input
ref={ref}
placeholder={placeholder}
{...(maxLength ? { maxlength: String(maxLength) } : {})}
{...(size ? { size } : {})}
{...(status ? { status } : {})}
{...(readOnly ? { readonly: '' } : {})}
/>
);
}
// usage
<AhaCountedInput value={answer} placeholder="Answer" maxLength={80} onChange={setAnswer} />
// main.ts — register the element + mark aha-* as custom elements
import '@ahaslides-product/design/aha-counted-input'; // registers <aha-counted-input>
app.config.compilerOptions.isCustomElement = (tag) => tag.startsWith('aha-');
// Component.vue
<script setup>
import { ref } from 'vue';
const answer = ref('');
</script>
<template>
<!-- size: small | default | large · maxlength turns the focus-only counter on -->
<aha-counted-input
size="default"
maxlength="80"
placeholder="Answer"
:value.prop="answer"
@input="answer = $event.detail.value"
/>
</template>
API
| Prop | Type | Default | Notes |
|---|---|---|---|
value | string | "" | Controlled text value |
placeholder | string | — | Hint shown when empty |
maxlength | number | 100 | Character cap (settings-lab default 100); drives the focus-only counter (shows current/max). Pass `none` to drop the cap and hide the counter |
size | small | default | large | default | Control height — small 24 · default 32 · large 40; radius stays 8 |
status | default | error | default | Error recolours the border + ring and sets aria-invalid |
disabled | boolean | false | Non-interactive; grey fill |
readonly | boolean | false | Selectable but not editable; secondary fill |
input | CustomEvent<{value}> | — | Composed event on each keystroke; read e.detail.value |
change | CustomEvent<{value}> | — | Composed event on commit (blur/enter) |
Install
# .npmrc — once: point the @ahaslides-product scope at GitHub Packages
@ahaslides-product:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN} # a GitHub token with read:packages
npm i @ahaslides-product/design
import '@ahaslides-product/design/tokens.css'; // once, at the app root
import '@ahaslides-product/design/aha-counted-input'; // registers <aha-counted-input>
Agent feed for this component (absolute, fetchable anywhere): counted-input.agent.json · counted-input.md · counted-input.llms.txt
When to use
When to use
- Counted input — a settings option/answer/label field that needs a character cap — the counter appears only on focus
- Counted textarea — the same, but multi-line (descriptions, long answers)
- Input — a general single-line field with no counter (names, search)
Never show a permanent counter on every field — it reads as heavy and steals width. The counter belongs inside the field, revealed on focus. Label the field with a noun phrase; use placeholder for an example, never as the label.
Surfaces
editor settings
Spec
Box height 32 (default) · radius 8 · padding 0 12 · Sizes small 24 · default 32 · large 40 — all radius 8 · Rest border 1px #E3E3E3 · Focus #6A1EBB border + 2px #D3B4FF@30% ring (on the persistent wrapper) · Counter 12/18 #8A8A8A, overlay inside the field, right 12; opacity 0 at rest → 1 on focus · Reveal focus-only (:host([_focused][_counted])) — hidden at rest; space always reserved (no shift) · Error #F5222D border + error-tinted ring; sets aria-invalid · Disabled #F1F1F1 fill, #EBEBEB border, not-allowed · Text Plus Jakarta 14/21; placeholder #8A8A8A