@finstack-com-public/design 0.8.0 → 0.9.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,6 +1,7 @@
1
1
  // Calendar: year, month and day views (spec 02 B, 03 §3.2, 06 §4; D42). The second helper that
2
2
  // builds its own markup, after the toaster: the cells change with every view and page. Dates are
3
- // ISO strings (`calendar-dates.ts`); every name and word is passed in.
3
+ // ISO strings (`calendar-dates.ts`); every name and word is passed in. `mode: 'range'` picks a start
4
+ // and an end with the same grid (T85), and `months: 2` shows two pages of the lowest view side by side.
4
5
  import { createIcon } from "../icons/index.js";
5
6
  import { addDays, addMonths, addYears, clampIso, daysInMonth, formatDay, formatMonth, localToday, monthGrid, parseDay, parseMonth, weekday, yearPage, } from "./calendar-dates.js";
6
7
  const VIEWS = {
@@ -11,18 +12,30 @@ const VIEWS = {
11
12
  const WIDTH = { day: 10, month: 7, year: 4 };
12
13
  const mod = (a, b) => ((a % b) + b) % b;
13
14
  let seq = 0;
14
- /** `root` is an empty `.fs-calendar` element; the helper renders the header and the grid into it. */
15
15
  export function createCalendar(root, options) {
16
16
  const doc = root.ownerDocument;
17
- const headingId = root.id ? `${root.id}-heading` : `fs-calendar-${++seq}-heading`;
17
+ const idBase = root.id || `fs-calendar-${++seq}`;
18
+ const headingId = `${idBase}-heading`;
19
+ const captionId = `${idBase}-caption`;
20
+ const isRange = options.mode === 'range';
18
21
  let opts = check({ granularity: 'day', weekStart: 1, ...options });
22
+ /** Single mode's value. */
19
23
  let value = null;
24
+ /** Range mode's ends; `end` is null while the second pick is pending. */
25
+ let start = null;
26
+ let end = null;
27
+ /** The lowest-view cell under the pointer, for the range preview. */
28
+ let hoverIso = null;
29
+ /** Whether a cell has focus, for the range preview. */
30
+ let gridFocused = false;
20
31
  let min;
21
32
  let max;
22
33
  let today = '';
23
34
  let view = opts.granularity ?? 'day';
24
35
  /** The cell with the tab stop, always at the granularity, whatever the view. */
25
36
  let focusIso = '';
37
+ /** A value on the first page shown; the others follow it. Empty: the focus's page. */
38
+ let pageStart = '';
26
39
  let lastHeading = '';
27
40
  let cellValues = new Map();
28
41
  const lowest = () => opts.granularity;
@@ -42,18 +55,37 @@ export function createCalendar(root, options) {
42
55
  return undefined;
43
56
  return formatDay(m.year, m.month, edge === 'first' ? 1 : daysInMonth(m.year, m.month));
44
57
  }
58
+ /** A range's ends at the granularity, in order; no start, no range. */
59
+ function readRange(v) {
60
+ const r = v && typeof v === 'object' ? v : null;
61
+ const s = read(r?.start, 'first') ?? null;
62
+ const e = read(r?.end, 'last') ?? null;
63
+ if (s === null)
64
+ return [null, null];
65
+ return e !== null && e < s ? [e, s] : [s, e];
66
+ }
45
67
  function readAll(next, first) {
46
68
  const granularityChanged = !first && next.granularity !== undefined && next.granularity !== lowest();
47
69
  opts = check({ ...opts, ...next });
70
+ if (isRange && !(opts.labels.rangeStart && opts.labels.rangeEnd)) {
71
+ throw new TypeError('[fs] createCalendar: a range needs labels.rangeStart and labels.rangeEnd');
72
+ }
48
73
  min = read(opts.min, 'first');
49
74
  max = read(opts.max, 'last');
50
75
  today = read(opts.today) ?? localToday(lowest());
51
- if (first || granularityChanged || 'value' in next)
52
- value = read(opts.value) ?? null;
76
+ if (first || granularityChanged || 'value' in next) {
77
+ if (isRange)
78
+ [start, end] = readRange(opts.value);
79
+ else
80
+ value = read(opts.value) ?? null;
81
+ hoverIso = null;
82
+ }
53
83
  if (first || granularityChanged)
54
84
  view = lowest();
55
- if (first || granularityChanged || 'value' in next || !focusIso)
56
- focusIso = clampIso(value ?? today, min, max);
85
+ if (first || granularityChanged || 'value' in next || !focusIso) {
86
+ focusIso = clampIso((isRange ? start : value) ?? today, min, max);
87
+ pageStart = '';
88
+ }
57
89
  }
58
90
  // The header, built once: its buttons keep focus across pages.
59
91
  const header = doc.createElement('div');
@@ -69,13 +101,24 @@ export function createCalendar(root, options) {
69
101
  const next = button('fs-icon-button fs-calendar__next');
70
102
  next.append(createIcon('chevron-right', { size: 16, document: doc }));
71
103
  header.append(viewButton, prev, next);
72
- const grid = doc.createElement('div');
73
- grid.setAttribute('role', 'grid');
104
+ /** The second page's heading, over its grid (two months, lowest view only). Not a control. */
105
+ const caption = doc.createElement('span');
106
+ caption.className = 'fs-calendar__caption';
107
+ caption.id = captionId;
108
+ const makeGrid = (labelledBy) => {
109
+ const g = doc.createElement('div');
110
+ g.setAttribute('role', 'grid');
111
+ g.setAttribute('aria-labelledby', labelledBy);
112
+ return g;
113
+ };
114
+ const grids = [makeGrid(headingId), makeGrid(captionId)];
115
+ /** Holds the grids when `months: 2`, so the calendar keeps its width in every view. */
116
+ const monthsEl = doc.createElement('div');
117
+ monthsEl.className = 'fs-calendar__months';
74
118
  /** The fallback live region, when the host passes no `announcer` (spec 06 §5). */
75
119
  const live = doc.createElement('span');
76
120
  live.className = 'fs-visually-hidden fs-calendar__live';
77
121
  live.setAttribute('aria-live', 'polite');
78
- grid.setAttribute('aria-labelledby', headingId);
79
122
  function button(className) {
80
123
  const b = doc.createElement('button');
81
124
  b.type = 'button';
@@ -119,17 +162,68 @@ export function createCalendar(root, options) {
119
162
  function settle(iso) {
120
163
  return pageOpen(pageOf(view, iso)) ? iso : clampIso(iso, min, max);
121
164
  }
122
- /** A cell button; only a day cell gets an aria-label (its full date), the others their text. */
165
+ /** How many pages the current view shows. */
166
+ const pages = () => (view === lowest() && opts.months === 2 ? 2 : 1);
167
+ /** Keeps the focus on a page shown: pages forward or back only when it leaves them. */
168
+ function follow() {
169
+ const n = pages();
170
+ if (n === 1 || !pageStart) {
171
+ pageStart = focusIso;
172
+ return;
173
+ }
174
+ const key = (iso) => pageRange(pageOf(view, iso))[0];
175
+ const f = key(focusIso);
176
+ if (f < key(pageStart))
177
+ pageStart = focusIso;
178
+ else if (f > key(page(view, pageStart, n - 1)))
179
+ pageStart = page(view, focusIso, 1 - n);
180
+ }
181
+ /** A cell's place in the range, compared on the cell's own width. */
182
+ function rangeRole(n, iso) {
183
+ if (!isRange || start === null)
184
+ return undefined;
185
+ const s = start.slice(0, n);
186
+ const e = (end ?? start).slice(0, n);
187
+ if (iso < s || iso > e)
188
+ return undefined;
189
+ if (s === e)
190
+ return end === null ? 'start' : 'both';
191
+ return iso === s ? 'start' : iso === e ? 'end' : 'inside';
192
+ }
193
+ /**
194
+ * A cell button; only a day cell gets an aria-label (its full date), the others are named by their
195
+ * text. In range mode the start and end words (`labels.rangeStart`, `rangeEnd`) follow the name: in
196
+ * a day's aria-label, else in a visually hidden span after the visible text, so the name always
197
+ * holds the text (WCAG 2.5.3) and a range is never colour alone.
198
+ */
123
199
  function makeCell(v, iso, text, label) {
124
200
  const el = button('fs-calendar__cell');
125
201
  el.setAttribute('role', 'gridcell');
126
202
  el.textContent = text;
127
- if (label !== undefined)
128
- el.setAttribute('aria-label', label);
129
203
  const n = WIDTH[v];
204
+ const role = rangeRole(n, iso);
205
+ const { rangeStart, rangeEnd } = opts.labels;
206
+ const said = role === 'start' ? [rangeStart] : role === 'end' ? [rangeEnd] : role === 'both' ? [rangeStart, rangeEnd] : [];
207
+ const suffix = said.map((w) => `, ${w}`).join('');
208
+ if (label !== undefined)
209
+ el.setAttribute('aria-label', label + suffix);
210
+ else if (suffix) {
211
+ const hidden = doc.createElement('span');
212
+ hidden.className = 'fs-visually-hidden';
213
+ hidden.textContent = suffix;
214
+ el.append(hidden);
215
+ }
130
216
  el.tabIndex = focusIso.slice(0, n) === iso ? 0 : -1;
131
- if (value !== null && value.slice(0, n) === iso)
217
+ if (isRange ? role !== undefined : value !== null && value.slice(0, n) === iso) {
132
218
  el.setAttribute('aria-selected', 'true');
219
+ }
220
+ // The band's shape: square where a cell meets the next one in the range.
221
+ if (role === 'inside')
222
+ el.classList.add('fs-calendar__cell--range');
223
+ else if (role === 'start' && end !== null)
224
+ el.classList.add('fs-calendar__cell--range-start');
225
+ else if (role === 'end')
226
+ el.classList.add('fs-calendar__cell--range-end');
133
227
  if (today.slice(0, n) === iso)
134
228
  el.setAttribute('aria-current', 'date');
135
229
  if (!enabled(v, iso))
@@ -150,11 +244,9 @@ export function createCalendar(root, options) {
150
244
  el.append(...children);
151
245
  return el;
152
246
  }
153
- function render(focusGrid = false) {
154
- const hadFocus = focusGrid || grid.contains(rootNode().activeElement);
155
- const current = pageOf(view, focusIso);
247
+ /** The rows of one page. */
248
+ function rowsOf(current) {
156
249
  const rows = [];
157
- cellValues = new Map();
158
250
  if (current.view === 'day') {
159
251
  const { year, month } = current;
160
252
  const ws = opts.weekStart;
@@ -190,15 +282,52 @@ export function createCalendar(root, options) {
190
282
  for (let i = 0; i < 12; i += 3)
191
283
  rows.push(row(units.slice(i, i + 3)));
192
284
  }
193
- grid.className = `fs-calendar__grid fs-calendar__grid--${view}`;
194
- grid.replaceChildren(...rows);
195
- const text = opts.heading(current);
196
- heading.textContent = text;
285
+ return rows;
286
+ }
287
+ /** Puts `children` into `parent` in order, touching nothing already in place. */
288
+ function place(parent, children) {
289
+ if (children.length !== parent.children.length || children.some((c, i) => parent.children[i] !== c)) {
290
+ parent.replaceChildren(...children);
291
+ }
292
+ }
293
+ function render(focusGrid = false) {
294
+ const hadFocus = focusGrid || grids.some((g) => g.contains(rootNode().activeElement));
295
+ follow();
296
+ const n = pages();
297
+ const shown = Array.from({ length: n }, (_, i) => pageOf(view, page(view, pageStart, i)));
298
+ cellValues = new Map();
299
+ shown.forEach((current, i) => {
300
+ grids[i].className = `fs-calendar__grid fs-calendar__grid--${view}`;
301
+ grids[i].replaceChildren(...rowsOf(current));
302
+ });
303
+ // One page: the grid straight after the header. Two: both in __months, which stays in every view.
304
+ if (opts.months === 2) {
305
+ grids[0].remove();
306
+ place(monthsEl, grids.slice(0, n));
307
+ if (header.nextElementSibling !== monthsEl)
308
+ header.after(monthsEl);
309
+ }
310
+ else {
311
+ monthsEl.remove();
312
+ if (header.nextElementSibling !== grids[0])
313
+ header.after(grids[0]);
314
+ }
315
+ if (n < 2)
316
+ grids[1].remove();
317
+ const texts = shown.map((p) => opts.heading(p));
318
+ heading.textContent = texts[0];
319
+ if (n === 2) {
320
+ caption.textContent = texts[1];
321
+ if (viewButton.nextElementSibling !== caption)
322
+ viewButton.after(caption);
323
+ }
324
+ else
325
+ caption.remove();
197
326
  const views = VIEWS[lowest()];
198
327
  const top = view === views[0];
199
328
  const up = view === 'year' ? undefined : opts.labels.up?.[view];
200
329
  if (up)
201
- viewButton.setAttribute('aria-label', `${text}, ${up}`);
330
+ viewButton.setAttribute('aria-label', `${texts[0]}, ${up}`);
202
331
  else
203
332
  viewButton.removeAttribute('aria-label');
204
333
  toggle(viewButton, 'aria-disabled', top);
@@ -208,10 +337,12 @@ export function createCalendar(root, options) {
208
337
  viewButton.append(viewIcon);
209
338
  prev.setAttribute('aria-label', opts.labels.prev[view]);
210
339
  next.setAttribute('aria-label', opts.labels.next[view]);
211
- toggle(prev, 'aria-disabled', !pageOpen(pageOf(view, page(view, focusIso, -1))) || isEdge(-1));
212
- toggle(next, 'aria-disabled', !pageOpen(pageOf(view, page(view, focusIso, 1))) || isEdge(1));
340
+ const last = page(view, pageStart, n - 1);
341
+ toggle(prev, 'aria-disabled', !pageOpen(pageOf(view, page(view, pageStart, -1))) || isEdge(pageStart, -1));
342
+ toggle(next, 'aria-disabled', !pageOpen(pageOf(view, page(view, last, 1))) || isEdge(last, 1));
213
343
  // Announce a new heading (paging, stepping), never the first one. Not from inside the view button:
214
344
  // a live region in a focused button whose name changes is read twice.
345
+ const text = texts.join(' – ');
215
346
  const out = opts.announcer ?? live;
216
347
  if (opts.announcer)
217
348
  live.remove();
@@ -220,12 +351,35 @@ export function createCalendar(root, options) {
220
351
  if (lastHeading && text !== lastHeading)
221
352
  out.textContent = text;
222
353
  lastHeading = text;
223
- if (hadFocus)
354
+ if (hadFocus) {
355
+ gridFocused = true;
224
356
  stopCell()?.focus();
357
+ }
358
+ paintPreview();
359
+ }
360
+ /**
361
+ * The range preview: while only the start is picked, the cells from it to the hovered cell (else
362
+ * the focused one, while the grid has focus) take `__cell--preview`. Classes only, no re-render.
363
+ */
364
+ function paintPreview() {
365
+ if (!isRange)
366
+ return;
367
+ let target = start !== null && end === null && view === lowest() ? (hoverIso ?? (gridFocused ? focusIso : null)) : null;
368
+ if (target !== null && !enabled(view, target))
369
+ target = null;
370
+ const [lo, hi] = target === null ? ['', ''] : target < start ? [target, start] : [start, target];
371
+ for (const [el, iso] of cellValues) {
372
+ el.classList.toggle('fs-calendar__cell--preview', target !== null && iso !== start && iso >= lo && iso <= hi);
373
+ }
225
374
  }
226
375
  /** At year 1 or 9999 paging goes nowhere. */
227
- function isEdge(dir) {
228
- return JSON.stringify(pageOf(view, page(view, focusIso, dir))) === JSON.stringify(pageOf(view, focusIso));
376
+ function isEdge(iso, dir) {
377
+ return JSON.stringify(pageOf(view, page(view, iso, dir))) === JSON.stringify(pageOf(view, iso));
378
+ }
379
+ /** Changes the view; the pages start again from the focus. */
380
+ function setViewTo(v) {
381
+ view = v;
382
+ pageStart = '';
229
383
  }
230
384
  function toggle(el, attr, on) {
231
385
  if (on)
@@ -246,8 +400,12 @@ export function createCalendar(root, options) {
246
400
  }
247
401
  return iso;
248
402
  }
249
- function moveTo(iso) {
403
+ /** Moves the focus; `pageTo` pages the pages shown too, so a pair pages together. */
404
+ function moveTo(iso, pageTo) {
250
405
  focusIso = settle(iso);
406
+ if (pageTo && pageStart)
407
+ pageStart = pageTo;
408
+ hoverIso = null; // the keyboard leads the preview now
251
409
  render(true);
252
410
  }
253
411
  function onKeydown(e) {
@@ -270,6 +428,7 @@ export function createCalendar(root, options) {
270
428
  return { back: index % 3, ahead: 2 - (index % 3) };
271
429
  };
272
430
  let to;
431
+ let pageTo;
273
432
  switch (e.key) {
274
433
  case 'ArrowRight':
275
434
  to = step(rtl ? -1 : 1);
@@ -292,14 +451,17 @@ export function createCalendar(root, options) {
292
451
  case 'PageUp':
293
452
  case 'PageDown': {
294
453
  const dir = e.key === 'PageUp' ? -1 : 1;
295
- to = e.shiftKey && view === 'day' ? addYears(focusIso, dir) : page(view, focusIso, dir);
454
+ const shift = (iso) => (e.shiftKey && view === 'day' ? addYears(iso, dir) : page(view, iso, dir));
455
+ to = shift(focusIso);
456
+ if (pageStart)
457
+ pageTo = shift(pageStart);
296
458
  break;
297
459
  }
298
460
  }
299
461
  if (to === undefined)
300
462
  return;
301
463
  e.preventDefault();
302
- moveTo(to);
464
+ moveTo(to, pageTo);
303
465
  }
304
466
  function onClick(e) {
305
467
  const target = e.target;
@@ -307,7 +469,7 @@ export function createCalendar(root, options) {
307
469
  const views = VIEWS[lowest()];
308
470
  const i = views.indexOf(view);
309
471
  if (i > 0) {
310
- view = views[i - 1];
472
+ setViewTo(views[i - 1]);
311
473
  render();
312
474
  }
313
475
  return;
@@ -319,6 +481,8 @@ export function createCalendar(root, options) {
319
481
  if (b.contains(target)) {
320
482
  if (b.getAttribute('aria-disabled') !== 'true') {
321
483
  focusIso = settle(page(view, focusIso, dir));
484
+ if (pageStart)
485
+ pageStart = page(view, pageStart, dir);
322
486
  render();
323
487
  }
324
488
  return;
@@ -328,6 +492,21 @@ export function createCalendar(root, options) {
328
492
  const iso = cell && cellValues.get(cell);
329
493
  if (!cell || !iso || cell.getAttribute('aria-disabled') === 'true')
330
494
  return;
495
+ if (view === lowest() && isRange) {
496
+ focusIso = iso;
497
+ // The first pick (or one after a complete range) is the start; the second the end, in order.
498
+ const completes = start !== null && end === null;
499
+ if (completes)
500
+ [start, end] = iso < start ? [iso, start] : [start, iso];
501
+ else
502
+ [start, end] = [iso, null];
503
+ render(true);
504
+ if (completes) {
505
+ const detail = { start: start, end: end };
506
+ root.dispatchEvent(new CustomEvent('fs-change', { bubbles: true, detail }));
507
+ }
508
+ return;
509
+ }
331
510
  if (view === lowest()) {
332
511
  value = iso;
333
512
  focusIso = iso;
@@ -337,24 +516,56 @@ export function createCalendar(root, options) {
337
516
  }
338
517
  focusIso = clampIso(onto(view, iso), min, max);
339
518
  const views = VIEWS[lowest()];
340
- view = views[views.indexOf(view) + 1];
519
+ setViewTo(views[views.indexOf(view) + 1]);
341
520
  render(true);
342
521
  }
343
522
  function onFocusin(e) {
344
523
  const iso = cellValues.get(e.target);
345
- if (iso === undefined || iso === focusIso.slice(0, WIDTH[view]))
524
+ if (iso === undefined)
525
+ return;
526
+ gridFocused = true;
527
+ if (iso !== focusIso.slice(0, WIDTH[view])) {
528
+ focusIso = onto(view, iso);
529
+ for (const el of cellValues.keys())
530
+ el.tabIndex = el === e.target ? 0 : -1;
531
+ }
532
+ paintPreview();
533
+ }
534
+ function onFocusout(e) {
535
+ if (!cellValues.has(e.target) || cellValues.has(e.relatedTarget))
536
+ return;
537
+ gridFocused = false;
538
+ paintPreview();
539
+ }
540
+ function onMouseover(e) {
541
+ const cell = e.target.closest?.('.fs-calendar__cell');
542
+ const iso = cell ? cellValues.get(cell) : undefined;
543
+ const over = iso !== undefined && view === lowest() ? iso : null;
544
+ if (over === hoverIso)
545
+ return;
546
+ hoverIso = over;
547
+ paintPreview();
548
+ }
549
+ function onMouseleave() {
550
+ if (hoverIso === null)
346
551
  return;
347
- focusIso = onto(view, iso);
348
- for (const el of cellValues.keys())
349
- el.tabIndex = el === e.target ? 0 : -1;
552
+ hoverIso = null;
553
+ paintPreview();
350
554
  }
555
+ const listeners = [
556
+ ['keydown', onKeydown],
557
+ ['click', onClick],
558
+ ['focusin', onFocusin],
559
+ ['focusout', onFocusout],
560
+ ['mouseover', onMouseover],
561
+ ['mouseleave', onMouseleave],
562
+ ];
351
563
  readAll(options, true);
352
- root.replaceChildren(header, grid);
564
+ root.replaceChildren(header);
353
565
  render();
354
- root.addEventListener('keydown', onKeydown);
355
- root.addEventListener('click', onClick);
356
- root.addEventListener('focusin', onFocusin);
357
- return {
566
+ for (const [type, fn] of listeners)
567
+ root.addEventListener(type, fn);
568
+ const controller = {
358
569
  get value() {
359
570
  return value;
360
571
  },
@@ -368,7 +579,7 @@ export function createCalendar(root, options) {
368
579
  setView(next) {
369
580
  if (!VIEWS[lowest()].includes(next))
370
581
  return;
371
- view = next;
582
+ setViewTo(next);
372
583
  render();
373
584
  },
374
585
  focus() {
@@ -379,13 +590,18 @@ export function createCalendar(root, options) {
379
590
  render();
380
591
  },
381
592
  destroy() {
382
- root.removeEventListener('keydown', onKeydown);
383
- root.removeEventListener('click', onClick);
384
- root.removeEventListener('focusin', onFocusin);
593
+ for (const [type, fn] of listeners)
594
+ root.removeEventListener(type, fn);
385
595
  root.replaceChildren();
386
596
  cellValues = new Map();
387
597
  },
388
598
  };
599
+ if (!isRange)
600
+ return controller;
601
+ // Range mode: the same controller, with the range as its value.
602
+ return Object.defineProperty(controller, 'value', {
603
+ get: () => (start === null ? null : { start, end }),
604
+ });
389
605
  }
390
606
  function check(o) {
391
607
  if (o.monthNames?.length !== 12)
@@ -1,4 +1,4 @@
1
- export { type Calendar, type CalendarChangeDetail, type CalendarDay, type CalendarLabels, type CalendarOptions, type CalendarPage, type CalendarView, createCalendar, type Granularity, } from './calendar.ts';
1
+ export { type Calendar, type CalendarChangeDetail, type CalendarDay, type CalendarLabels, type CalendarOptions, type CalendarPage, type CalendarRange, type CalendarRangeChangeDetail, type CalendarRangeLabels, type CalendarView, createCalendar, type Granularity, type RangeCalendar, type RangeCalendarOptions, } from './calendar.ts';
2
2
  export { createDialog, createSheet, type Dialog, type DialogCloseDetail, type DialogOptions } from './dialog.ts';
3
3
  export { createListbox, type Listbox, type ListboxOptions, type ListboxSelectDetail } from './listbox.ts';
4
4
  export { createLoader, type Loader, type LoaderOptions } from './loader.ts';
@@ -68,7 +68,8 @@ export function createListbox(list, options) {
68
68
  view.addEventListener('scroll', reposition, true);
69
69
  emit('fs-open');
70
70
  }
71
- function close() {
71
+ // `silent` is internal (destroy()): the caller ended it on purpose, so nothing is emitted (T88).
72
+ function teardown(silent) {
72
73
  if (!open)
73
74
  return;
74
75
  open = false;
@@ -81,7 +82,11 @@ export function createListbox(list, options) {
81
82
  doc.removeEventListener('pointerdown', onOutside, true);
82
83
  view.removeEventListener('resize', reposition);
83
84
  view.removeEventListener('scroll', reposition, true);
84
- emit('fs-close');
85
+ if (!silent)
86
+ emit('fs-close');
87
+ }
88
+ function close() {
89
+ teardown(false);
85
90
  }
86
91
  function accept(option) {
87
92
  if (isDisabled(option))
@@ -191,7 +196,7 @@ export function createListbox(list, options) {
191
196
  reposition();
192
197
  },
193
198
  destroy() {
194
- close();
199
+ teardown(true);
195
200
  unbind();
196
201
  list.removeEventListener('pointerdown', onListPointerdown);
197
202
  list.removeEventListener('click', onListClick);
@@ -4,7 +4,7 @@
4
4
  export function createLoader(loader, options = {}) {
5
5
  let running = false;
6
6
  loader.hidden = true;
7
- const set = (on) => {
7
+ const set = (on, silent = false) => {
8
8
  running = on;
9
9
  loader.hidden = !on;
10
10
  if (options.area) {
@@ -13,7 +13,8 @@ export function createLoader(loader, options = {}) {
13
13
  else
14
14
  options.area.removeAttribute('aria-busy');
15
15
  }
16
- loader.dispatchEvent(new CustomEvent(on ? 'fs-open' : 'fs-close', { bubbles: true }));
16
+ if (!silent)
17
+ loader.dispatchEvent(new CustomEvent(on ? 'fs-open' : 'fs-close', { bubbles: true }));
17
18
  };
18
19
  return {
19
20
  get isRunning() {
@@ -21,6 +22,6 @@ export function createLoader(loader, options = {}) {
21
22
  },
22
23
  start: () => !running && set(true),
23
24
  stop: () => running && set(false),
24
- destroy: () => running && set(false),
25
+ destroy: () => running && set(false, true),
25
26
  };
26
27
  }
package/dist/dom/menu.js CHANGED
@@ -56,7 +56,8 @@ export function createMenu(menu, options = {}) {
56
56
  view.addEventListener('scroll', onViewportChange, true);
57
57
  emit('fs-open');
58
58
  }
59
- function close({ returnFocus = true } = {}) {
59
+ // `silent` is internal (destroy()): the caller ended it on purpose, so nothing is emitted (T88).
60
+ function teardown(returnFocus, silent) {
60
61
  if (!open)
61
62
  return;
62
63
  open = false;
@@ -70,7 +71,11 @@ export function createMenu(menu, options = {}) {
70
71
  view.removeEventListener('scroll', onViewportChange, true);
71
72
  if (returnFocus)
72
73
  (opts.trigger ?? returnTo)?.focus();
73
- emit('fs-close');
74
+ if (!silent)
75
+ emit('fs-close');
76
+ }
77
+ function close({ returnFocus = true } = {}) {
78
+ teardown(returnFocus, false);
74
79
  }
75
80
  function choose(item) {
76
81
  if (isDisabled(item))
@@ -204,7 +209,7 @@ export function createMenu(menu, options = {}) {
204
209
  opts.trigger?.addEventListener('keydown', onTriggerKeydown);
205
210
  opts.trigger?.addEventListener('click', onTriggerClick);
206
211
  opts.trigger?.setAttribute('aria-haspopup', 'menu');
207
- opts.trigger?.setAttribute('aria-expanded', 'false');
212
+ opts.trigger?.setAttribute('aria-expanded', String(open));
208
213
  if (opts.trigger && menu.id)
209
214
  opts.trigger.setAttribute('aria-controls', menu.id);
210
215
  opts.contextTarget?.addEventListener('contextmenu', onContextmenu);
@@ -239,7 +244,7 @@ export function createMenu(menu, options = {}) {
239
244
  i.setAttribute('tabindex', '-1');
240
245
  },
241
246
  destroy() {
242
- close({ returnFocus: false });
247
+ teardown(false, true);
243
248
  unbind();
244
249
  menu.removeEventListener('keydown', onMenuKeydown);
245
250
  menu.removeEventListener('click', onMenuClick);
@@ -37,7 +37,8 @@ export function createPopover(panel, options) {
37
37
  view.addEventListener('scroll', reposition, true);
38
38
  emit('fs-open');
39
39
  }
40
- function close({ returnFocus = true } = {}) {
40
+ // `silent` is internal (destroy()): the caller ended it on purpose, so nothing is emitted (T88).
41
+ function teardown(returnFocus, silent) {
41
42
  if (!open)
42
43
  return;
43
44
  open = false;
@@ -50,7 +51,11 @@ export function createPopover(panel, options) {
50
51
  view.removeEventListener('scroll', reposition, true);
51
52
  if (returnFocus)
52
53
  opts.anchor.focus();
53
- emit('fs-close');
54
+ if (!silent)
55
+ emit('fs-close');
56
+ }
57
+ function close({ returnFocus = true } = {}) {
58
+ teardown(returnFocus, false);
54
59
  }
55
60
  function onOutside(e) {
56
61
  const path = e.composedPath();
@@ -74,7 +79,7 @@ export function createPopover(panel, options) {
74
79
  const onAnchorClick = () => (open ? close() : show());
75
80
  function bind() {
76
81
  opts.anchor.addEventListener('click', onAnchorClick);
77
- opts.anchor.setAttribute('aria-expanded', 'false');
82
+ opts.anchor.setAttribute('aria-expanded', String(open));
78
83
  if (panel.id)
79
84
  opts.anchor.setAttribute('aria-controls', panel.id);
80
85
  if (opts.focus === 'panel' && !panel.hasAttribute('tabindex'))
@@ -94,7 +99,7 @@ export function createPopover(panel, options) {
94
99
  reposition();
95
100
  },
96
101
  destroy() {
97
- close({ returnFocus: false });
102
+ teardown(false, true);
98
103
  opts.anchor.removeEventListener('click', onAnchorClick);
99
104
  },
100
105
  };