@kolkrabbi/kol-component 0.280.0 → 0.281.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.280.0",
3
+ "version": "0.281.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,6 +19,13 @@ import ToggleCheckbox from '../atoms/ToggleCheckbox.jsx'
19
19
  * stay OK / Cancel, existing callers untouched (ModalConfirmLabels,
20
20
  * 2026-08-12). Enter/Escape keep their meanings regardless of labels.
21
21
  *
22
+ * PASSWORD (ModalPromptPassword, kol-atlas 2026-10-19): `prompt(title, '', { type: 'password' })`
23
+ * masks the field (`autoComplete="current-password"`) for the family's sign-in prompts. The
24
+ * native fallback cannot mask — mount a ModalProvider. `placeholder` sits in the same options.
25
+ *
26
+ * KEYBOARD: the dialog opens focused (prompt → its field, confirm/alert → OK), Tab cycles inside
27
+ * it, and Enter on a focused button presses that button rather than submitting.
28
+ *
22
29
  * Returned promise resolves to:
23
30
  * - prompt → string (value) on submit, `null` on cancel
24
31
  * - confirm → boolean: `true` on confirm, `false` on cancel
@@ -58,8 +65,8 @@ export function ModalProvider({ children }) {
58
65
  })
59
66
  }, [])
60
67
 
61
- const prompt = useCallback((title, defaultValue = '', { okLabel, cancelLabel } = {}) =>
62
- new Promise((resolve) => setState({ kind: 'prompt', title, defaultValue, okLabel, cancelLabel, resolve })),
68
+ const prompt = useCallback((title, defaultValue = '', { okLabel, cancelLabel, type = 'text', placeholder } = {}) =>
69
+ new Promise((resolve) => setState({ kind: 'prompt', title, defaultValue, okLabel, cancelLabel, type, placeholder, resolve })),
63
70
  [])
64
71
 
65
72
  const confirm = useCallback((title, { okLabel, cancelLabel, options } = {}) =>
@@ -85,6 +92,7 @@ function ModalView({ state, closeWith }) {
85
92
  const [val, setVal] = useState(state.defaultValue ?? '')
86
93
  const [values, setValues] = useState(() => Object.fromEntries((state.options ?? []).map((o) => [o.id, !!o.defaultValue])))
87
94
  const inputRef = useRef(null)
95
+ const dialogRef = useRef(null)
88
96
 
89
97
  /* alert resolves `undefined` whichever way it is dismissed; a confirm with toggles resolves
90
98
  * `{ ok, values }` */
@@ -92,11 +100,24 @@ function ModalView({ state, closeWith }) {
92
100
  const submit = () => closeWith(state.kind === 'prompt' ? val : state.kind === 'alert' ? undefined : answer(true))
93
101
  const cancel = () => closeWith(state.kind === 'prompt' ? null : state.kind === 'alert' ? undefined : answer(false))
94
102
 
103
+ /* focus once on open — the key effect below re-runs per keystroke and would steal it back */
95
104
  useEffect(() => {
96
105
  if (state.kind === 'prompt') inputRef.current?.focus()
106
+ else dialogRef.current?.querySelector('[data-modal-ok]')?.focus()
107
+ }, [state.kind])
108
+
109
+ useEffect(() => {
97
110
  const onKey = (e) => {
98
111
  if (e.key === 'Escape') cancel()
99
- if (e.key === 'Enter') submit()
112
+ if (e.key === 'Enter' && e.target.tagName !== 'BUTTON') submit()
113
+ if (e.key === 'Tab') {
114
+ const els = [...(dialogRef.current?.querySelectorAll('button, input') ?? [])].filter((el) => !el.disabled)
115
+ if (!els.length) return
116
+ const i = els.indexOf(document.activeElement)
117
+ const next = e.shiftKey ? (i <= 0 ? els.length - 1 : i - 1) : (i === els.length - 1 ? 0 : i + 1)
118
+ e.preventDefault()
119
+ els[next].focus()
120
+ }
100
121
  }
101
122
  window.addEventListener('keydown', onKey)
102
123
  return () => window.removeEventListener('keydown', onKey)
@@ -115,6 +136,10 @@ function ModalView({ state, closeWith }) {
115
136
  }}
116
137
  >
117
138
  <div
139
+ ref={dialogRef}
140
+ role={state.kind === 'prompt' ? 'dialog' : 'alertdialog'}
141
+ aria-modal="true"
142
+ aria-labelledby="kol-modal-title"
118
143
  onMouseDown={(e) => e.stopPropagation()}
119
144
  className="kol-modal flex flex-col gap-4 p-5 rounded border border-fg-08"
120
145
  style={{
@@ -127,10 +152,13 @@ function ModalView({ state, closeWith }) {
127
152
  {/* kol-mono-12, not helper: dialog copy WRAPS, and helper's
128
153
  * line-height 1 is single-line chrome only (type protocol). */}
129
154
  {/* pre-line: an alert can carry a failure list, one per line */}
130
- <p className="kol-mono-12 text-emphasis whitespace-pre-line">{state.title}</p>
155
+ <p id="kol-modal-title" className="kol-mono-12 text-emphasis whitespace-pre-line">{state.title}</p>
131
156
  {state.kind === 'prompt' && (
132
157
  <Input
133
158
  ref={inputRef}
159
+ type={state.type}
160
+ autoComplete={state.type === 'password' ? 'current-password' : undefined}
161
+ placeholder={state.placeholder}
134
162
  variant="outline"
135
163
  size="sm"
136
164
  value={val}
@@ -153,7 +181,9 @@ function ModalView({ state, closeWith }) {
153
181
  )}
154
182
  <div className="flex gap-2 justify-end">
155
183
  {state.kind !== 'alert' && <Button size="sm" onClick={cancel}>{state.cancelLabel ?? 'Cancel'}</Button>}
156
- <Button tone="primary" size="sm" onClick={submit}>{state.okLabel ?? 'OK'}</Button>
184
+ {/* inverted, not primary: since tone-is-the-ground-axis (2026-09-03) primary is the
185
+ * dark ground, so OK drew the same as Cancel and nothing showed what Enter does */}
186
+ <Button tone="inverted" size="sm" onClick={submit} data-modal-ok>{state.okLabel ?? 'OK'}</Button>
157
187
  </div>
158
188
  </div>
159
189
  </div>