@human-kit/ui 1.3.0 → 1.4.1

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.
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { useAutocompleteContext } from '../root/context';
3
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
3
4
 
4
5
  /**
5
6
  * Autocomplete.Status - Visually-hidden live region that announces the number
@@ -15,9 +16,6 @@
15
16
  count === 0 ? 'No results available' : `${count} result${count === 1 ? '' : 's'} available`
16
17
  }: AutocompleteStatusProps = $props();
17
18
 
18
- const visuallyHiddenStyle =
19
- 'position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
20
-
21
19
  const ctx = useAutocompleteContext();
22
20
  const message = $derived(formatMessage(ctx.visibleCount));
23
21
  </script>
@@ -7,6 +7,7 @@
7
7
  } from '../../primitives/input-modality';
8
8
  import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
9
9
  import { cn } from '../../utils/cn';
10
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
10
11
 
11
12
  export type ButtonRenderState = {
12
13
  hovered: boolean;
@@ -429,13 +430,14 @@
429
430
  <!--
430
431
  The polite live region is a sibling of the button, not a child: inside the button its text
431
432
  would be concatenated into the button's computed accessible name ("Saving Saving, pending").
432
- Visually hidden via inline styles because the library is headless.
433
+ Visually hidden with the shared fixed-position style: an absolute one inside a scroll
434
+ container made Chrome promote the sticky content around it to its own layer, which blurred
435
+ its text.
433
436
  -->
434
437
  <span
435
438
  data-button-live-region="true"
436
439
  role="status"
437
440
  aria-live="polite"
438
441
  aria-atomic="true"
439
- style="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;"
440
- >{pendingAnnouncement}</span
442
+ style={visuallyHiddenStyle}>{pendingAnnouncement}</span
441
443
  >
@@ -60,7 +60,15 @@ export type TimeSelectionState = {
60
60
  */
61
61
  readonly isInvalidDraft: boolean;
62
62
  getSegmentValue: (type: TimePickerEditableSegmentType) => string;
63
- setSegmentValue: (type: TimePickerEditableSegmentType, nextValue: string) => void;
63
+ /**
64
+ * Writes one segment and commits. The draft is held inside min/max unless `clamp` is
65
+ * `false`: a first digit still waiting for its pair is not a time yet.
66
+ */
67
+ setSegmentValue: (type: TimePickerEditableSegmentType, nextValue: string, options?: {
68
+ clamp?: boolean;
69
+ }) => void;
70
+ /** Holds the draft inside min/max and commits it: a pending digit that was left alone. */
71
+ clampDraft: () => void;
64
72
  /** Re-commits the current draft (publishes `null` when it is not committeable). */
65
73
  commitDraft: () => void;
66
74
  /**
@@ -166,12 +166,44 @@ export function createTimeSelectionState(options) {
166
166
  return segmentDraft.second;
167
167
  return segmentDraft.dayPeriod;
168
168
  }
169
- function setSegmentValue(type, nextValue) {
169
+ function setSegmentValue(type, nextValue, { clamp = true } = {}) {
170
170
  if (!options.isEditable())
171
171
  return;
172
172
  writeSegmentValue(type, nextValue);
173
+ if (clamp)
174
+ clampDraftToRange();
173
175
  commitFromDraft();
174
176
  }
177
+ function clampDraft() {
178
+ if (!options.isEditable())
179
+ return;
180
+ clampDraftToRange();
181
+ commitFromDraft();
182
+ }
183
+ /**
184
+ * Holds a typed or stepped draft inside `minValue`/`maxValue`, the way React Aria's
185
+ * segments hold a number inside its bounds: a complete time past the max becomes the
186
+ * max, one before the min becomes the min, at once rather than on blur. A first digit
187
+ * that waits for its pair is skipped (`1` on the way to `19` under a `10:00` min), and
188
+ * held once it is completed or left alone.
189
+ */
190
+ function clampDraftToRange() {
191
+ const granularity = options.granularity();
192
+ const parts = buildTimePartsFromDraft(segmentDraft, granularity, resolvedHourCycle);
193
+ if (!parts)
194
+ return;
195
+ const candidate = formatTimePickerValue(parts, granularity);
196
+ let boundary;
197
+ if (isTimeOutOfRange(candidate, undefined, normalizedMaxValue, granularity)) {
198
+ boundary = normalizedMaxValue;
199
+ }
200
+ else if (isTimeOutOfRange(candidate, normalizedMinValue, undefined, granularity)) {
201
+ boundary = normalizedMinValue;
202
+ }
203
+ if (!boundary)
204
+ return;
205
+ segmentDraft = toDraftFromTimeValue(boundary, resolvedHourCycle);
206
+ }
175
207
  /** Normalizes and writes a segment into the draft without committing it. */
176
208
  function writeSegmentValue(type, nextValue) {
177
209
  options.onBeforeSegmentMutation?.(type);
@@ -385,6 +417,7 @@ export function createTimeSelectionState(options) {
385
417
  },
386
418
  getSegmentValue,
387
419
  setSegmentValue,
420
+ clampDraft,
388
421
  commitDraft: commitFromDraft,
389
422
  setValue,
390
423
  selectWheelValue,
@@ -2,6 +2,7 @@
2
2
  import type { Snippet } from 'svelte';
3
3
  import type { HTMLAttributes } from 'svelte/elements';
4
4
  import { resolveLocalizedString } from '../../internal/localized-strings';
5
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
5
6
  import { useClockContext, type ClockEditableSegmentType } from '../root/context';
6
7
  import TimePickerWheelItem from '../wheel-item/clock-wheel-item.svelte';
7
8
  import { useWheelScroll, type WheelScrollBehavior } from '../hooks/use-wheel-scroll.svelte';
@@ -506,18 +507,13 @@
506
507
  >
507
508
  <div data-wheel-spacer="top" style={`height:${spacerHeight}px`}></div>
508
509
  <!--
509
- Visually-hidden live region using inline styles so the headless library
510
+ Visually-hidden live region using the shared inline style so the headless library
510
511
  does not depend on an external `sr-only` utility class (e.g. Tailwind).
511
512
  Kept in addition to aria-valuetext: valuetext changes are only announced
512
513
  while the spinbutton has DOM focus, whereas this also covers pointer and
513
514
  touch scrolling without focus.
514
515
  -->
515
- <span
516
- role="status"
517
- aria-live="polite"
518
- style="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0"
519
- >{valueText}</span
520
- >
516
+ <span role="status" aria-live="polite" style={visuallyHiddenStyle}>{valueText}</span>
521
517
  {#each options as option, index (option.value)}
522
518
  {#if children}
523
519
  {@render children(option, selectedValue === option.value)}
@@ -3,6 +3,7 @@
3
3
  import { resolveLocalizedString } from '../../internal/localized-strings';
4
4
  import { useLocaleContextOptional } from '../../locale-provider/context';
5
5
  import { useComboBoxContext } from '../root/context';
6
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
6
7
 
7
8
  /**
8
9
  * ComboBox.Status - Visually-hidden live region that announces the number of
@@ -25,9 +26,6 @@
25
26
 
26
27
  const ctx = useComboBoxContext();
27
28
 
28
- const visuallyHiddenStyle =
29
- 'position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
30
-
31
29
  const defaultMessage = $derived.by(() => {
32
30
  const count = ctx.visibleCount;
33
31
  if (count === 0) return resolveLocalizedString($localeStore, 'combobox.noResults');
@@ -2,6 +2,7 @@
2
2
  import { untrack, type Snippet } from 'svelte';
3
3
  import type { HTMLButtonAttributes } from 'svelte/elements';
4
4
  import { shouldShowFocusVisible, trackInteractionModality } from '../primitives/input-modality';
5
+ import { visuallyHiddenStyle } from '../primitives/visually-hidden';
5
6
  import type { ClassValue } from '../utils/cn';
6
7
  import { composeEventHandlers } from '../utils/compose-event-handlers';
7
8
 
@@ -315,10 +316,6 @@
315
316
  onchange={handleInputChange}
316
317
  />
317
318
 
318
- <span
319
- role="status"
320
- aria-live="polite"
321
- aria-atomic="true"
322
- style="position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;"
319
+ <span role="status" aria-live="polite" aria-atomic="true" style={visuallyHiddenStyle}
323
320
  >{announcement}</span
324
321
  >
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Inline style for content that only assistive technology reads, such as a live region.
3
+ * Inline, because the library is headless and must not depend on an `sr-only` class.
4
+ *
5
+ * `position: fixed`, not `absolute`: an absolutely positioned element inside a scroll container
6
+ * that is not itself positioned is laid out against an ancestor outside the scroller. While the
7
+ * container scrolls, Chrome then promotes the content around it (a sticky header, say) to its own
8
+ * compositing layer to keep the element in place, and that layer drops subpixel anti-aliasing
9
+ * from its text. A fixed element is laid out against the viewport and never escapes a scroller.
10
+ *
11
+ * Native form controls that stand in for a custom one (a hidden `<input>` or `<select>`) keep
12
+ * their own absolute style: the browser anchors its validation bubble to them, so they have to
13
+ * stay where the visible control is.
14
+ */
15
+ export declare const visuallyHiddenStyle = "position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;";
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Inline style for content that only assistive technology reads, such as a live region.
3
+ * Inline, because the library is headless and must not depend on an `sr-only` class.
4
+ *
5
+ * `position: fixed`, not `absolute`: an absolutely positioned element inside a scroll container
6
+ * that is not itself positioned is laid out against an ancestor outside the scroller. While the
7
+ * container scrolls, Chrome then promotes the content around it (a sticky header, say) to its own
8
+ * compositing layer to keep the element in place, and that layer drops subpixel anti-aliasing
9
+ * from its text. A fixed element is laid out against the viewport and never escapes a scroller.
10
+ *
11
+ * Native form controls that stand in for a custom one (a hidden `<input>` or `<select>`) keep
12
+ * their own absolute style: the browser anchors its validation bubble to them, so they have to
13
+ * stay where the visible control is.
14
+ */
15
+ export const visuallyHiddenStyle = 'position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
@@ -10,7 +10,7 @@
10
10
  useTableContext
11
11
  } from '../root/context.svelte';
12
12
  import type { TableColumnResizerProps } from '../types.js';
13
- import { visuallyHiddenStyle } from '../utils/visually-hidden-style';
13
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
14
14
  import {
15
15
  shouldShowFocusVisible,
16
16
  trackInteractionModality
@@ -22,7 +22,7 @@
22
22
  trackInteractionModality
23
23
  } from '../../primitives/input-modality';
24
24
  import { watchFocusVisible } from '../../primitives/focus-visible.svelte';
25
- import { visuallyHiddenStyle } from '../utils/visually-hidden-style';
25
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
26
26
  import type { TableRootProps } from '../types.js';
27
27
  import {
28
28
  createTableContext,
@@ -28,7 +28,9 @@ export type TimePickerContext = {
28
28
  setValue: (nextValue: TimePickerTimeValue | null) => void;
29
29
  getSegments: () => TimePickerSegmentPart[];
30
30
  getSegmentValue: (type: Exclude<TimePickerSegmentType, 'literal'>) => string;
31
- setSegmentValue: (type: Exclude<TimePickerSegmentType, 'literal'>, nextValue: string) => void;
31
+ setSegmentValue: (type: Exclude<TimePickerSegmentType, 'literal'>, nextValue: string, options?: {
32
+ clamp?: boolean;
33
+ }) => void;
32
34
  typeSegmentDigit: (type: Exclude<TimePickerSegmentType, 'literal'>, digit: string) => boolean;
33
35
  adjustSegmentValue: (type: Exclude<TimePickerSegmentType, 'literal'>, step: number) => void;
34
36
  getSegmentLabel: (type: TimePickerEditableSegmentType) => string;
@@ -197,6 +197,7 @@
197
197
  if (!nextWithin && activeSegment !== null) {
198
198
  activeSegment = null;
199
199
  segmentTypeBuffer = createEmptyTimePickerDraft();
200
+ timeSelection.clampDraft();
200
201
  }
201
202
  if (focusWithin === nextWithin) return;
202
203
  focusWithin = nextWithin;
@@ -206,6 +207,8 @@
206
207
  if (activeSegment === segment) return;
207
208
  activeSegment = segment;
208
209
  segmentTypeBuffer = createEmptyTimePickerDraft();
210
+ // A digit left waiting, or one erased, is held to min/max once the segment is left.
211
+ timeSelection.clampDraft();
209
212
  }
210
213
 
211
214
  function openPopover(reason: TimePickerOpenChangeReason = 'imperative-action', event?: Event) {
@@ -246,14 +249,11 @@
246
249
 
247
250
  const threshold = getTypingThreshold(type);
248
251
  if (candidate.length === 1) {
249
- timeSelection.setSegmentValue(type, candidate);
250
- segmentTypeBuffer[type] = candidate;
251
- const numeric = Number(candidate);
252
- if (Number.isFinite(numeric) && numeric >= threshold) {
253
- segmentTypeBuffer[type] = '';
254
- return true;
255
- }
256
- return false;
252
+ // A digit that waits for its pair is not held to min/max yet: `1` on the way to `19`.
253
+ const completes = Number(candidate) >= threshold;
254
+ timeSelection.setSegmentValue(type, candidate, { clamp: completes });
255
+ segmentTypeBuffer[type] = completes ? '' : candidate;
256
+ return completes;
257
257
  }
258
258
 
259
259
  const numericCandidate = Number(candidate);
@@ -271,14 +271,10 @@
271
271
 
272
272
  if (numericCandidate < min || numericCandidate > max) {
273
273
  candidate = digit;
274
- timeSelection.setSegmentValue(type, candidate);
275
- segmentTypeBuffer[type] = candidate;
276
- const fallbackNumeric = Number(candidate);
277
- if (fallbackNumeric >= threshold) {
278
- segmentTypeBuffer[type] = '';
279
- return true;
280
- }
281
- return false;
274
+ const completes = Number(candidate) >= threshold;
275
+ timeSelection.setSegmentValue(type, candidate, { clamp: completes });
276
+ segmentTypeBuffer[type] = completes ? '' : candidate;
277
+ return completes;
282
278
  }
283
279
 
284
280
  timeSelection.setSegmentValue(type, candidate);
@@ -308,7 +308,8 @@
308
308
  }
309
309
  return;
310
310
  }
311
- timePicker.setSegmentValue(segment.type, currentValue.slice(0, -1));
311
+ // Erasing is on the way to typing: held to min/max once the segment is left.
312
+ timePicker.setSegmentValue(segment.type, currentValue.slice(0, -1), { clamp: false });
312
313
  return;
313
314
  }
314
315
 
@@ -8,7 +8,7 @@
8
8
  import { getFocusableElements } from '../../primitives/focus-trap';
9
9
  import { shouldShowFocusVisible } from '../../primitives/input-modality';
10
10
  import { SWIPE_IGNORE_ATTRIBUTE } from '../../primitives/swipe-gesture';
11
- import { visuallyHiddenStyle } from '../../table/utils/visually-hidden-style';
11
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
12
12
  import { useToastProviderContext } from '../provider/context';
13
13
  import type { ToastItem } from '../provider/toast-manager.svelte';
14
14
  import type { ToastViewportProps } from '../types.js';
@@ -4,6 +4,7 @@
4
4
  import { useLocaleContextOptional } from '../../locale-provider/context';
5
5
  import { useTransferListContext } from '../root/context';
6
6
  import type { TransferListMoveDetails } from '../root/types';
7
+ import { visuallyHiddenStyle } from '../../primitives/visually-hidden';
7
8
 
8
9
  /**
9
10
  * TransferList.Status - Visually-hidden live region that announces each move.
@@ -25,9 +26,6 @@
25
26
 
26
27
  const ctx = useTransferListContext('TransferList.Status');
27
28
 
28
- const visuallyHiddenStyle =
29
- 'position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
30
-
31
29
  const message = $derived.by(() => {
32
30
  const move = ctx.lastMove;
33
31
  if (!move) return '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@human-kit/ui",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Accessible, typed UI components for Svelte 5 — shipped as native ESM with per-component subpath exports so bundlers only include what you import.",
5
5
  "license": "MIT",
6
6
  "author": "Agustin Delgado <agustindariodelgado@gmail.com>",
@@ -1 +0,0 @@
1
- export declare const visuallyHiddenStyle = "position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;";
@@ -1 +0,0 @@
1
- export const visuallyHiddenStyle = 'position:fixed;top:0;left:0;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';