@tooark/web-components 1.3.0 → 1.5.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/dist/index.js CHANGED
@@ -322,7 +322,8 @@ const PERSON_SVG = `
322
322
  * carregar, as iniciais de `name` (primeira letra, ou primeira mais última
323
323
  * quando há sobrenome); sem nome e sem imagem, um glifo de pessoa decorativo
324
324
  * (`aria-hidden`, a menos que o host tenha aria-label próprio). `color` troca
325
- * o tint primary por uma cor própria (texto na cor, fundo suave).
325
+ * o tint primary por uma cor própria (texto na cor, fundo suave) e
326
+ * `variant="solid"` preenche o fundo com a cor e escreve as iniciais em branco.
326
327
  */
327
328
  class ArkAvatar extends HTMLElementBase {
328
329
  constructor() {
@@ -337,7 +338,7 @@ class ArkAvatar extends HTMLElementBase {
337
338
  this.ownLabel = null;
338
339
  }
339
340
  static get observedAttributes() {
340
- return ["name", "src", "size", "shape", "color", "aria-label", "theme", "class", "testid"];
341
+ return ["name", "src", "size", "shape", "color", "variant", "aria-label", "theme", "class", "testid"];
341
342
  }
342
343
  connectedCallback() {
343
344
  upgradeProperties(this);
@@ -378,6 +379,9 @@ class ArkAvatar extends HTMLElementBase {
378
379
  getShape() {
379
380
  return (this.getAttribute("shape") || "").toLowerCase() === "square" ? "square" : "circle";
380
381
  }
382
+ getVariant() {
383
+ return (this.getAttribute("variant") || "").toLowerCase() === "solid" ? "solid" : "soft";
384
+ }
381
385
  render() {
382
386
  const initials = document.createElement("span");
383
387
  initials.setAttribute("aria-hidden", "true");
@@ -416,7 +420,7 @@ class ArkAvatar extends HTMLElementBase {
416
420
  this.imageEl.hidden = failed;
417
421
  this.imageEl.className = failed ? "" : "ark:h-full ark:w-full ark:object-cover";
418
422
  }
419
- // Cor própria: texto na cor e fundo suave por color-mix, como o badge.
423
+ // Cor própria, como o badge: suave é texto na cor e fundo por color-mix; sólido é fundo na cor e texto branco.
420
424
  applyCustomColor() {
421
425
  const color = this.getAttribute("color")?.trim();
422
426
  if (!color) {
@@ -424,8 +428,9 @@ class ArkAvatar extends HTMLElementBase {
424
428
  this.style.removeProperty("--ark-avatar-fg");
425
429
  return;
426
430
  }
427
- this.style.setProperty("--ark-avatar-bg", `color-mix(in oklab, ${color} 18%, transparent)`);
428
- this.style.setProperty("--ark-avatar-fg", color);
431
+ const solid = this.getVariant() === "solid";
432
+ this.style.setProperty("--ark-avatar-bg", solid ? color : `color-mix(in oklab, ${color} 18%, transparent)`);
433
+ this.style.setProperty("--ark-avatar-fg", solid ? "#fff" : color);
429
434
  }
430
435
  applyOwnClasses(next) {
431
436
  this.syncingClass = true;
@@ -467,7 +472,9 @@ class ArkAvatar extends HTMLElementBase {
467
472
  ].join(" ");
468
473
  const colors = this.getAttribute("color")?.trim()
469
474
  ? "ark:bg-(--ark-avatar-bg) ark:text-(--ark-avatar-fg)"
470
- : "ark:bg-primary-soft ark:text-primary-soft-fg";
475
+ : this.getVariant() === "solid"
476
+ ? "ark:bg-primary ark:text-primary-fg"
477
+ : "ark:bg-primary-soft ark:text-primary-soft-fg";
471
478
  this.applyOwnClasses([
472
479
  "ark:inline-flex ark:shrink-0 ark:items-center ark:justify-center ark:overflow-hidden ark:align-middle ark:font-semibold ark:uppercase ark:leading-none ark:select-none",
473
480
  sizing.box,
@@ -2534,8 +2541,10 @@ let nextId$1 = 0;
2534
2541
  * formulário; os dois são controles nativos, então <fieldset disabled> os
2535
2542
  * desabilita sem JS. `label` vira um <label for> próprio; sem ele o host
2536
2543
  * precisa de aria-label, ou de filhos (texto livre, links), que dão nome à
2537
- * caixa por aria-labelledby e a alternam ao clique. Os nós próprios ficam no
2538
- * início do host, marcados data-ark-chrome, antes dos filhos do usuário.
2544
+ * caixa por aria-labelledby e a alternam ao clique. `helper` acrescenta uma
2545
+ * dica abaixo do rótulo, que descreve a caixa por aria-describedby. Os nós
2546
+ * próprios ficam no início do host, marcados data-ark-chrome, antes dos filhos
2547
+ * do usuário.
2539
2548
  */
2540
2549
  class ArkCheckbox extends HTMLElementBase {
2541
2550
  static get observedAttributes() {
@@ -2546,6 +2555,7 @@ class ArkCheckbox extends HTMLElementBase {
2546
2555
  "name",
2547
2556
  "value",
2548
2557
  "label",
2558
+ "helper",
2549
2559
  "aria-label",
2550
2560
  "size",
2551
2561
  "intent",
@@ -2561,6 +2571,7 @@ class ArkCheckbox extends HTMLElementBase {
2561
2571
  this.boxEl = null;
2562
2572
  this.iconEl = null;
2563
2573
  this.labelEl = null;
2574
+ this.helperEl = null;
2564
2575
  this.inputEl = null;
2565
2576
  this.observer = null;
2566
2577
  /** Glifo em exibição; a troca depois do primeiro render entra com scale-in. */
@@ -2715,11 +2726,11 @@ class ArkCheckbox extends HTMLElementBase {
2715
2726
  getSizing() {
2716
2727
  const size = (this.getAttribute("size") || "md").toLowerCase();
2717
2728
  const sizes = {
2718
- xs: { box: "ark:h-3.5 ark:w-3.5 ark:p-px", label: "ark:text-xs" },
2719
- sm: { box: "ark:h-4 ark:w-4 ark:p-px", label: "ark:text-sm" },
2720
- md: { box: "ark:h-5 ark:w-5 ark:p-0.5", label: "ark:text-sm" },
2721
- lg: { box: "ark:h-6 ark:w-6 ark:p-0.5", label: "ark:text-base" },
2722
- xl: { box: "ark:h-7 ark:w-7 ark:p-1", label: "ark:text-lg" }
2729
+ xs: { box: "ark:h-3.5 ark:w-3.5 ark:p-px", label: "ark:text-xs", helper: "ark:text-2xs" },
2730
+ sm: { box: "ark:h-4 ark:w-4 ark:p-px", label: "ark:text-sm", helper: "ark:text-xs" },
2731
+ md: { box: "ark:h-5 ark:w-5 ark:p-0.5", label: "ark:text-sm", helper: "ark:text-xs" },
2732
+ lg: { box: "ark:h-6 ark:w-6 ark:p-0.5", label: "ark:text-base", helper: "ark:text-sm" },
2733
+ xl: { box: "ark:h-7 ark:w-7 ark:p-1", label: "ark:text-lg", helper: "ark:text-base" }
2723
2734
  };
2724
2735
  return sizes[size] ?? sizes.md;
2725
2736
  }
@@ -2741,7 +2752,8 @@ class ArkCheckbox extends HTMLElementBase {
2741
2752
  input.tabIndex = -1;
2742
2753
  input.setAttribute("aria-hidden", "true");
2743
2754
  input.setAttribute("data-ark-chrome", "input");
2744
- // No início do host: a caixa antes do rótulo na ordem de leitura; o input oculto não conta.
2755
+ // No início do host: a caixa antes do rótulo na ordem de leitura; o input oculto não conta. A caixa vem antes
2756
+ // do input porque um <label> do app em volta do host rotula o primeiro controle rotulável dentro dele.
2745
2757
  this.prepend(box, input);
2746
2758
  this.boxEl = box;
2747
2759
  this.iconEl = icon;
@@ -2763,7 +2775,32 @@ class ArkCheckbox extends HTMLElementBase {
2763
2775
  }
2764
2776
  this.labelEl.htmlFor = this.boxEl?.id ?? "";
2765
2777
  this.labelEl.textContent = text;
2766
- this.labelEl.className = ["ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
2778
+ this.labelEl.className = ["ark:col-start-2 ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
2779
+ }
2780
+ // Dica própria: um <span> depois do rótulo, só enquanto `helper` existir, que descreve a caixa por aria-describedby.
2781
+ // Com ela o host vira grid (updateAppearance): a caixa na primeira coluna, rótulo e dica empilhados na segunda.
2782
+ syncHelper(sizing) {
2783
+ if (!this.boxEl)
2784
+ return;
2785
+ const text = this.getAttribute("helper");
2786
+ if (!text) {
2787
+ this.helperEl?.remove();
2788
+ this.helperEl = null;
2789
+ this.boxEl.removeAttribute("aria-describedby");
2790
+ return;
2791
+ }
2792
+ if (!this.helperEl) {
2793
+ const helper = document.createElement("span");
2794
+ helper.setAttribute("data-ark-chrome", "helper");
2795
+ helper.id = `${this.boxEl.id}-helper`;
2796
+ (this.labelEl ?? this.inputEl)?.after(helper);
2797
+ this.helperEl = helper;
2798
+ }
2799
+ if (this.helperEl.textContent !== text)
2800
+ this.helperEl.textContent = text;
2801
+ // order: 1 põe a dica depois do rótulo livre do usuário, que vem depois dos nós próprios.
2802
+ this.helperEl.className = ["ark:col-start-2 ark:order-1 ark:text-fg-muted", sizing.helper].join(" ");
2803
+ this.boxEl.setAttribute("aria-describedby", this.helperEl.id);
2767
2804
  }
2768
2805
  // Nome acessível da caixa: o <label for> próprio; senão aria-label; senão os filhos do usuário, via
2769
2806
  // aria-labelledby no host (que ganha um id quando falta).
@@ -2791,6 +2828,16 @@ class ArkCheckbox extends HTMLElementBase {
2791
2828
  this.boxEl.removeAttribute("aria-label");
2792
2829
  this.boxEl.removeAttribute("aria-labelledby");
2793
2830
  }
2831
+ // Nomeada pelo host, a dica entraria no nome: sai da árvore e segue como descrição (aria-describedby alcança
2832
+ // nós ocultos).
2833
+ if (this.helperEl) {
2834
+ if (this.boxEl.getAttribute("aria-labelledby") === this.id) {
2835
+ this.helperEl.setAttribute("aria-hidden", "true");
2836
+ }
2837
+ else {
2838
+ this.helperEl.removeAttribute("aria-hidden");
2839
+ }
2840
+ }
2794
2841
  }
2795
2842
  syncIcon(kind) {
2796
2843
  if (!this.iconEl || kind === this.iconKind)
@@ -2826,11 +2873,20 @@ class ArkCheckbox extends HTMLElementBase {
2826
2873
  const checked = this.checked;
2827
2874
  const indeterminate = this.indeterminate;
2828
2875
  const disabled = this.disabled;
2876
+ // Com `helper` o host é grid: caixa na primeira coluna, rótulo e dica empilhados na segunda.
2877
+ const layout = this.hasAttribute("helper")
2878
+ ? "ark:inline-grid ark:grid-cols-[auto_minmax(0,1fr)] ark:gap-x-2 ark:gap-y-0.5"
2879
+ : "ark:inline-flex ark:gap-2";
2829
2880
  // O host dimeriza tudo (caixa e rótulo) quando qualquer controle interno está desabilitado, inclusive
2830
2881
  // por <fieldset disabled>.
2831
- this.applyOwnClasses("ark:inline-flex ark:cursor-pointer ark:items-center ark:gap-2 ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50".split(" "));
2882
+ this.applyOwnClasses([
2883
+ layout,
2884
+ "ark:cursor-pointer ark:items-center ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50"
2885
+ ]
2886
+ .join(" ")
2887
+ .split(" "));
2832
2888
  this.boxEl.className = [
2833
- "ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-sm ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
2889
+ "ark:col-start-1 ark:row-start-1 ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-sm ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
2834
2890
  palette.ring,
2835
2891
  sizing.box,
2836
2892
  checked || indeterminate
@@ -2841,6 +2897,7 @@ class ArkCheckbox extends HTMLElementBase {
2841
2897
  this.boxEl.disabled = disabled;
2842
2898
  this.syncIcon(indeterminate ? "mixed" : checked ? "check" : "none");
2843
2899
  this.syncLabel(sizing);
2900
+ this.syncHelper(sizing);
2844
2901
  this.syncName();
2845
2902
  this.inputEl.checked = checked;
2846
2903
  this.inputEl.indeterminate = indeterminate;
@@ -2851,6 +2908,8 @@ class ArkCheckbox extends HTMLElementBase {
2851
2908
  applyTestHooks(this, "checkbox", this.inputEl, "input");
2852
2909
  if (this.labelEl)
2853
2910
  applyTestHooks(this, "checkbox", this.labelEl, "label");
2911
+ if (this.helperEl)
2912
+ applyTestHooks(this, "checkbox", this.helperEl, "helper");
2854
2913
  }
2855
2914
  }
2856
2915
  ArkCheckbox.tagName = "ark-checkbox";
@@ -3443,7 +3502,9 @@ function normalize(text) {
3443
3502
  * e um listbox oculto que é dono das opções visíveis por `aria-owns`. Itens
3444
3503
  * e cabeçalhos se ordenam por `order` no CSS, então nada é inserido entre os
3445
3504
  * filhos. Com `filter` o texto filtra localmente pelo `label` dos itens; em
3446
- * qualquer caso `ark-query` sai com debounce para busca assíncrona. O foco
3505
+ * qualquer caso `ark-query` sai com debounce para busca assíncrona. Sem opções
3506
+ * visíveis a mensagem é `noResults`; `hint` a troca enquanto o campo está
3507
+ * vazio e `busy` (busca em andamento) a troca por `searching`. O foco
3447
3508
  * fica sempre no campo; setas movem a opção ativa (`aria-activedescendant`),
3448
3509
  * Enter seleciona, Esc fecha; `hotkey` abre de qualquer lugar da página. A
3449
3510
  * página para de rolar enquanto aberta, salvo com `no-scroll-lock`.
@@ -3457,6 +3518,8 @@ class ArkCommandPalette extends HTMLElementBase {
3457
3518
  "filter",
3458
3519
  "query-delay",
3459
3520
  "label",
3521
+ "hint",
3522
+ "busy",
3460
3523
  "theme",
3461
3524
  "lang",
3462
3525
  "locale-json",
@@ -3658,6 +3721,13 @@ class ArkCommandPalette extends HTMLElementBase {
3658
3721
  set noScrollLock(value) {
3659
3722
  this.toggleAttribute("no-scroll-lock", coerceBooleanAttr(value));
3660
3723
  }
3724
+ /** Busca assíncrona em andamento (atributo `busy`): o listbox fica `aria-busy` e, sem opções, aparece `searching`. */
3725
+ get busy() {
3726
+ return this.hasAttribute("busy");
3727
+ }
3728
+ set busy(value) {
3729
+ this.toggleAttribute("busy", coerceBooleanAttr(value));
3730
+ }
3661
3731
  /** Texto atual do campo de busca. */
3662
3732
  get query() {
3663
3733
  return this.inputEl?.value ?? "";
@@ -3741,15 +3811,31 @@ class ArkCommandPalette extends HTMLElementBase {
3741
3811
  applyTestHooks(this, "command-palette", header, "group");
3742
3812
  });
3743
3813
  this.listEl.setAttribute("aria-owns", visible.map((item) => item.id).join(" "));
3744
- this.emptyEl.hidden = visible.length > 0;
3745
- const noResults = this.getLocale().noResults;
3746
- if (this.emptyEl.textContent !== noResults)
3747
- this.emptyEl.textContent = noResults;
3814
+ this.syncEmpty(visible.length);
3748
3815
  const enabled = visible.filter((item) => !item.disabled);
3749
3816
  if (!enabled.some((item) => item.id === this.activeId))
3750
3817
  this.activeId = enabled[0]?.id ?? null;
3751
3818
  this.applyActive(items);
3752
3819
  }
3820
+ // Mensagem sem opções visíveis: `searching` com `busy`, o `hint` do app com o campo vazio, senão `noResults`.
3821
+ syncEmpty(visible) {
3822
+ if (!this.listEl || !this.emptyEl)
3823
+ return;
3824
+ const locale = this.getLocale();
3825
+ const busy = this.busy;
3826
+ const hint = this.getAttribute("hint");
3827
+ const text = busy ? locale.searching : hint && this.query.trim() === "" ? hint : locale.noResults;
3828
+ this.emptyEl.hidden = visible > 0;
3829
+ // Só escreve o que mudou: o observer (subtree) veria a troca do nó de texto e sincronizaria em laço.
3830
+ if (this.emptyEl.textContent !== text)
3831
+ this.emptyEl.textContent = text;
3832
+ if (busy) {
3833
+ this.listEl.setAttribute("aria-busy", "true");
3834
+ }
3835
+ else {
3836
+ this.listEl.removeAttribute("aria-busy");
3837
+ }
3838
+ }
3753
3839
  applyActive(items) {
3754
3840
  for (const item of items) {
3755
3841
  const active = item.id === this.activeId;
@@ -3910,8 +3996,7 @@ class ArkCommandPalette extends HTMLElementBase {
3910
3996
  this.inputEl.removeAttribute(attr);
3911
3997
  }
3912
3998
  }
3913
- if (this.emptyEl.textContent !== locale.noResults)
3914
- this.emptyEl.textContent = locale.noResults;
3999
+ this.syncEmpty(this.visibleItems().length);
3915
4000
  applyTestHooks(this, "command-palette", this);
3916
4001
  applyTestHooks(this, "command-palette", this.inputEl, "input");
3917
4002
  applyTestHooks(this, "command-palette", this.listEl, "list");
@@ -5145,11 +5230,12 @@ function cssLength$1(value) {
5145
5230
  * página e só anima (o console inferior, um painel lateral fixo). Os filhos
5146
5231
  * do usuário são o corpo e ficam onde estão; um filho `slot="footer"` vai ao
5147
5232
  * fim por CSS. O cabeçalho (título `h2` de `label` e botão de fechar) é o
5148
- * primeiro filho, marcado `data-ark-chrome`. `side` escolhe a borda, a
5149
- * direção do slide (com o easing `sheet`) e a borda desenhada; `size` é um
5150
- * preset ou um comprimento CSS no eixo da gaveta. `open` é a fonte da
5151
- * verdade, como no ark-dialog, e em overlay a página para de rolar enquanto
5152
- * aberta, salvo com `no-scroll-lock`.
5233
+ * primeiro filho, marcado `data-ark-chrome`; um container `slot="actions"`
5234
+ * entra na linha dele por CSS, entre o título e o fechar. `side` escolhe a
5235
+ * borda, a direção do slide (com o easing `sheet`) e a borda desenhada;
5236
+ * `size` é um preset ou um comprimento CSS no eixo da gaveta. `open` é a fonte
5237
+ * da verdade, como no ark-dialog, e em overlay a página para de rolar
5238
+ * enquanto aberta, salvo com `no-scroll-lock`.
5153
5239
  */
5154
5240
  class ArkDrawer extends HTMLElementBase {
5155
5241
  static get observedAttributes() {
@@ -5174,6 +5260,10 @@ class ArkDrawer extends HTMLElementBase {
5174
5260
  this.titleEl = null;
5175
5261
  this.closeEl = null;
5176
5262
  this.observer = null;
5263
+ /** Mede o filho `slot="actions"`: a largura dele é o espaço que o título deixa livre na linha do cabeçalho. */
5264
+ this.actionsObserver = null;
5265
+ /** O filho `slot="actions"` que o actionsObserver mede. */
5266
+ this.observedActions = null;
5177
5267
  this.ownClasses = [];
5178
5268
  this.syncingClass = false;
5179
5269
  this.state = "closed";
@@ -5198,7 +5288,8 @@ class ArkDrawer extends HTMLElementBase {
5198
5288
  connectedCallback() {
5199
5289
  upgradeProperties(this);
5200
5290
  if (!this.observer) {
5201
- this.observer = new MutationObserver(() => this.syncFooter());
5291
+ // Rodapé e ações que chegam depois (frameworks) ganham o hook; as ações também mudam o cabeçalho.
5292
+ this.observer = new MutationObserver(() => this.updateAppearance());
5202
5293
  this.observer.observe(this, { childList: true });
5203
5294
  }
5204
5295
  this.updateAppearance();
@@ -5211,6 +5302,9 @@ class ArkDrawer extends HTMLElementBase {
5211
5302
  disconnectedCallback() {
5212
5303
  this.observer?.disconnect();
5213
5304
  this.observer = null;
5305
+ this.actionsObserver?.disconnect();
5306
+ this.actionsObserver = null;
5307
+ this.observedActions = null;
5214
5308
  this.releaseTrap?.();
5215
5309
  this.releaseTrap = null;
5216
5310
  unlockScroll(this);
@@ -5422,8 +5516,8 @@ class ArkDrawer extends HTMLElementBase {
5422
5516
  .split(/\s+/)
5423
5517
  .filter(Boolean);
5424
5518
  }
5425
- syncHeader(label, showClose) {
5426
- if (!label && !showClose) {
5519
+ syncHeader(label, showClose, withActions) {
5520
+ if (!label && !showClose && !withActions) {
5427
5521
  this.headerEl?.remove();
5428
5522
  this.headerEl = null;
5429
5523
  this.titleEl = null;
@@ -5436,8 +5530,14 @@ class ArkDrawer extends HTMLElementBase {
5436
5530
  this.prepend(header);
5437
5531
  this.headerEl = header;
5438
5532
  }
5439
- this.headerEl.className =
5440
- "ark:sticky ark:top-0 ark:z-10 ark:-mx-6 ark:flex ark:items-start ark:gap-4 ark:bg-surface ark:px-6 ark:pt-6 ark:pb-4";
5533
+ // As ações vêm antes do cabeçalho (order) e ocupam 3rem até o fim da linha do título: ele sobe por cima desse
5534
+ // espaço e guarda ao menos a altura dessa linha.
5535
+ this.headerEl.className = [
5536
+ "ark:sticky ark:top-0 ark:z-10 ark:-mx-6 ark:flex ark:items-start ark:gap-4 ark:bg-surface ark:px-6 ark:pt-6 ark:pb-4",
5537
+ withActions ? "ark:-mt-12 ark:min-h-16" : ""
5538
+ ]
5539
+ .join(" ")
5540
+ .trim();
5441
5541
  if (label) {
5442
5542
  if (!this.titleEl) {
5443
5543
  const title = document.createElement("h2");
@@ -5446,7 +5546,13 @@ class ArkDrawer extends HTMLElementBase {
5446
5546
  this.titleEl = title;
5447
5547
  }
5448
5548
  this.titleEl.textContent = label;
5449
- this.titleEl.className = "ark:min-w-0 ark:flex-1 ark:text-base ark:leading-6 ark:font-semibold ark:text-fg";
5549
+ // Com ações, o título deixa livre a largura medida delas mais o espaço entre as duas.
5550
+ this.titleEl.className = [
5551
+ "ark:min-w-0 ark:flex-1 ark:text-base ark:leading-6 ark:font-semibold ark:text-fg",
5552
+ withActions ? "ark:me-[calc(var(--ark-drawer-actions-width,0px)+1rem)]" : ""
5553
+ ]
5554
+ .join(" ")
5555
+ .trim();
5450
5556
  }
5451
5557
  else {
5452
5558
  this.titleEl?.remove();
@@ -5477,6 +5583,28 @@ class ArkDrawer extends HTMLElementBase {
5477
5583
  if (footer)
5478
5584
  applyTestHooks(this, "drawer", footer, "footer");
5479
5585
  }
5586
+ // Passa a medir o filho `slot="actions"` atual (ou nenhum). Sem ResizeObserver (SSR, jsdom) o título não reserva
5587
+ // a largura delas, só o espaço entre os dois.
5588
+ syncActions(actions) {
5589
+ if (actions)
5590
+ applyTestHooks(this, "drawer", actions, "actions");
5591
+ if (actions === this.observedActions)
5592
+ return;
5593
+ this.actionsObserver?.disconnect();
5594
+ this.observedActions = actions;
5595
+ if (!actions) {
5596
+ this.style.removeProperty("--ark-drawer-actions-width");
5597
+ return;
5598
+ }
5599
+ if (typeof ResizeObserver === "undefined")
5600
+ return;
5601
+ if (!this.actionsObserver) {
5602
+ this.actionsObserver = new ResizeObserver(() => {
5603
+ this.style.setProperty("--ark-drawer-actions-width", `${this.observedActions?.offsetWidth ?? 0}px`);
5604
+ });
5605
+ }
5606
+ this.actionsObserver.observe(actions);
5607
+ }
5480
5608
  applyOwnClasses(next) {
5481
5609
  this.syncingClass = true;
5482
5610
  for (const cls of this.ownClasses) {
@@ -5513,7 +5641,9 @@ class ArkDrawer extends HTMLElementBase {
5513
5641
  this.setAttribute("tabindex", "-1");
5514
5642
  this.setAttribute("data-ark-side", this.side);
5515
5643
  this.setAttribute("data-ark-mode", this.mode);
5516
- this.syncHeader(label, !this.hasAttribute("no-close-button"));
5644
+ const actions = this.querySelector(':scope > [slot="actions"]');
5645
+ this.syncHeader(label, !this.hasAttribute("no-close-button"), actions !== null);
5646
+ this.syncActions(actions);
5517
5647
  // Nome acessível: o título; sem ele um aria-label do usuário fica.
5518
5648
  if (label && this.titleEl) {
5519
5649
  this.setAttribute("aria-labelledby", this.titleId);
@@ -5662,7 +5792,10 @@ const UPLOAD_SVG = `
5662
5792
  * seletor nativo e soltar arquivos na zona alimenta o mesmo input. Toda
5663
5793
  * mudança emite `change` com os arquivos e anuncia os nomes ao leitor de
5664
5794
  * tela. O rótulo aponta para o input (associação nativa) e nomeia o botão
5665
- * junto do próprio texto dele.
5795
+ * junto do próprio texto dele. Com `directory` o campo escolhe uma pasta: o
5796
+ * seletor abre em modo pasta, uma pasta solta é lida até o fim, a lista vira
5797
+ * um resumo e `change` leva também o caminho de cada arquivo. Sem ele, uma
5798
+ * pasta solta é recusada com aviso.
5666
5799
  */
5667
5800
  class ArkFileInput extends HTMLElementBase {
5668
5801
  constructor() {
@@ -5676,14 +5809,18 @@ class ArkFileInput extends HTMLElementBase {
5676
5809
  this.messageEl = null;
5677
5810
  /** Profundidade de dragenter/dragleave, porque eles disparam também nos filhos da zona. */
5678
5811
  this.dragDepth = 0;
5812
+ /** O último drop trouxe uma pasta que o campo não aceita: a lista mostra o aviso até a próxima seleção. */
5813
+ this.folderRejected = false;
5814
+ /** Caminho de cada arquivo vindo de um drop em modo pasta, na ordem de `files`; nulo quando veio do seletor. */
5815
+ this.droppedPaths = null;
5816
+ /** Conta as seleções: a leitura assíncrona de uma pasta solta só é publicada se nada veio depois dela. */
5817
+ this.selectionSeq = 0;
5679
5818
  // --- Interação ---
5680
5819
  // O change nativo do input oculto não sobe ao host: quem escuta no host recebe só o CustomEvent com detail.
5681
5820
  this.handleChange = (event) => {
5682
- event?.stopPropagation();
5683
- this.syncList();
5684
- const files = this.files;
5685
- announce(files.length ? files.map((file) => file.name).join(", ") : this.getLocale().noFile);
5686
- this.dispatchEvent(new CustomEvent("change", { detail: { files }, bubbles: true, composed: true }));
5821
+ event.stopPropagation();
5822
+ this.resetSelection();
5823
+ this.publish();
5687
5824
  };
5688
5825
  this.handleDragEnter = (event) => {
5689
5826
  if (this.isDisabled())
@@ -5706,28 +5843,46 @@ class ArkFileInput extends HTMLElementBase {
5706
5843
  if (this.dragDepth === 0)
5707
5844
  this.setDragover(false);
5708
5845
  };
5709
- // Soltar alimenta o mesmo input (FileList é atribuível): só o primeiro arquivo sem `multiple`.
5846
+ // Soltar alimenta o mesmo input (FileList é atribuível): só o primeiro arquivo sem `multiple`. Uma pasta não é um
5847
+ // arquivo (o navegador a entrega como um File vazio, que não dá para ler): sem `directory` fica de fora, com aviso
5848
+ // na lista e anúncio; com ele é lida até o fim.
5710
5849
  this.handleDrop = (event) => {
5711
5850
  if (this.isDisabled())
5712
5851
  return;
5713
5852
  event.preventDefault();
5714
5853
  this.dragDepth = 0;
5715
5854
  this.setDragover(false);
5716
- const dropped = event.dataTransfer?.files;
5717
- if (!dropped || dropped.length === 0 || !this.inputEl)
5855
+ if (!event.dataTransfer || !this.inputEl)
5856
+ return;
5857
+ const { files, folders } = ArkFileInput.readDrop(event.dataTransfer);
5858
+ if (files.length === 0 && folders.length === 0)
5859
+ return;
5860
+ if (this.directory) {
5861
+ void this.selectDropped(files, folders);
5862
+ return;
5863
+ }
5864
+ if (files.length === 0) {
5865
+ // Só pastas: a seleção fica como estava e não há `change`.
5866
+ this.folderRejected = true;
5867
+ this.syncList();
5868
+ announce(this.getLocale().foldersNotAccepted);
5718
5869
  return;
5870
+ }
5871
+ this.resetSelection();
5872
+ this.folderRejected = folders.length > 0;
5719
5873
  const transfer = new DataTransfer();
5720
- const count = this.multiple ? dropped.length : 1;
5874
+ const count = this.multiple ? files.length : 1;
5721
5875
  for (let index = 0; index < count; index += 1)
5722
- transfer.items.add(dropped[index]);
5876
+ transfer.items.add(files[index]);
5723
5877
  this.inputEl.files = transfer.files;
5724
- this.handleChange();
5878
+ this.publish();
5725
5879
  };
5726
5880
  }
5727
5881
  static get observedAttributes() {
5728
5882
  return [
5729
5883
  "accept",
5730
5884
  "multiple",
5885
+ "directory",
5731
5886
  "label",
5732
5887
  "helper",
5733
5888
  "error",
@@ -5763,6 +5918,21 @@ class ArkFileInput extends HTMLElementBase {
5763
5918
  get files() {
5764
5919
  return Array.from(this.inputEl?.files ?? []);
5765
5920
  }
5921
+ /**
5922
+ * Caminho de cada arquivo de `files`, na mesma ordem, a partir da pasta escolhida ou solta (`pasta/sub/a.txt`);
5923
+ * o nome do arquivo quando ele não veio de uma pasta.
5924
+ */
5925
+ get paths() {
5926
+ const dropped = this.droppedPaths;
5927
+ return this.files.map((file, index) => dropped?.[index] ?? (file.webkitRelativePath || file.name));
5928
+ }
5929
+ /** Escolhe uma pasta inteira: o seletor abre em modo pasta e a zona lê as pastas soltas. Padrão: desligado. */
5930
+ get directory() {
5931
+ return this.hasAttribute("directory");
5932
+ }
5933
+ set directory(value) {
5934
+ this.toggleAttribute("directory", coerceBooleanAttr(value));
5935
+ }
5766
5936
  get multiple() {
5767
5937
  return this.hasAttribute("multiple");
5768
5938
  }
@@ -5780,6 +5950,7 @@ class ArkFileInput extends HTMLElementBase {
5780
5950
  if (!this.inputEl)
5781
5951
  return;
5782
5952
  this.inputEl.value = "";
5953
+ this.resetSelection();
5783
5954
  this.syncList();
5784
5955
  }
5785
5956
  focus(options) {
@@ -5792,6 +5963,106 @@ class ArkFileInput extends HTMLElementBase {
5792
5963
  isDisabled() {
5793
5964
  return this.buttonEl ? this.buttonEl.matches(":disabled") : this.disabled;
5794
5965
  }
5966
+ // Uma seleção nova (seletor, drop ou clear) descarta o aviso, os caminhos do drop anterior e a leitura em curso.
5967
+ resetSelection() {
5968
+ this.folderRejected = false;
5969
+ this.droppedPaths = null;
5970
+ this.selectionSeq += 1;
5971
+ }
5972
+ // Lista, anúncio e `change` da seleção atual do input. Em modo pasta o anúncio é o resumo e `detail` leva os
5973
+ // caminhos; fora dele o detail é só `{ files }`, como sempre foi.
5974
+ publish() {
5975
+ this.syncList();
5976
+ const files = this.files;
5977
+ const locale = this.getLocale();
5978
+ if (this.directory) {
5979
+ const summary = this.summarize(locale);
5980
+ announce(files.length ? [summary.folder, summary.count].filter(Boolean).join(", ") : locale.noFolder);
5981
+ const detail = { files, paths: this.paths };
5982
+ this.dispatchEvent(new CustomEvent("change", { detail, bubbles: true, composed: true }));
5983
+ return;
5984
+ }
5985
+ const selection = files.length ? files.map((file) => file.name).join(", ") : locale.noFile;
5986
+ announce(this.folderRejected ? `${selection}. ${locale.foldersNotAccepted}` : selection);
5987
+ this.dispatchEvent(new CustomEvent("change", { detail: { files }, bubbles: true, composed: true }));
5988
+ }
5989
+ // Resumo da seleção em modo pasta: o nome da pasta, quando todos os caminhos saem da mesma, a contagem e o tamanho.
5990
+ summarize(locale) {
5991
+ const files = this.files;
5992
+ const roots = new Set(this.paths.map((path) => (path.includes("/") ? path.slice(0, path.indexOf("/")) : "")));
5993
+ const [root = ""] = roots;
5994
+ return {
5995
+ folder: roots.size === 1 ? root : "",
5996
+ count: locale.fileCount.replace("{count}", String(files.length)),
5997
+ size: files.reduce((total, file) => total + file.size, 0)
5998
+ };
5999
+ }
6000
+ // Separa arquivos e pastas de um drop. A pasta só se distingue pela entrada (webkitGetAsEntry), que existe só
6001
+ // durante o evento; sem a API, ou num DataTransfer montado por código, tudo é arquivo.
6002
+ static readDrop(transfer) {
6003
+ const files = [];
6004
+ const folders = [];
6005
+ const items = Array.from(transfer.items ?? []);
6006
+ if (items.length === 0)
6007
+ return { files: Array.from(transfer.files ?? []), folders };
6008
+ for (const item of items) {
6009
+ if (item.kind !== "file")
6010
+ continue;
6011
+ const entry = typeof item.webkitGetAsEntry === "function" ? item.webkitGetAsEntry() : null;
6012
+ if (entry?.isDirectory) {
6013
+ folders.push(entry);
6014
+ continue;
6015
+ }
6016
+ const file = item.getAsFile();
6017
+ if (file)
6018
+ files.push(file);
6019
+ }
6020
+ return { files, folders };
6021
+ }
6022
+ // Lê uma pasta solta até o fim, descendo nas subpastas. readEntries devolve lotes (100 no Chromium), então é
6023
+ // chamado até vir vazio; uma entrada que falha ao ler fica de fora sem derrubar o resto.
6024
+ static async readFolder(folder, prefix, found) {
6025
+ const reader = folder.createReader();
6026
+ for (;;) {
6027
+ const batch = await new Promise((resolve) => {
6028
+ reader.readEntries(resolve, () => resolve([]));
6029
+ });
6030
+ if (batch.length === 0)
6031
+ return;
6032
+ for (const entry of batch) {
6033
+ const path = `${prefix}${entry.name}`;
6034
+ if (entry.isDirectory) {
6035
+ await ArkFileInput.readFolder(entry, `${path}/`, found);
6036
+ }
6037
+ else if (entry.isFile) {
6038
+ const file = await new Promise((resolve) => {
6039
+ entry.file(resolve, () => resolve(null));
6040
+ });
6041
+ if (file)
6042
+ found.push({ file, path });
6043
+ }
6044
+ }
6045
+ }
6046
+ }
6047
+ // Drop em modo pasta: as pastas são lidas até o fim e tudo vai para o input, cada arquivo de pasta com o caminho a
6048
+ // partir do nome dela (como o webkitRelativePath do seletor) e os arquivos soltos junto com o próprio nome.
6049
+ async selectDropped(files, folders) {
6050
+ this.resetSelection();
6051
+ const seq = this.selectionSeq;
6052
+ const found = files.map((file) => ({ file, path: file.name }));
6053
+ for (const folder of folders)
6054
+ await ArkFileInput.readFolder(folder, `${folder.name}/`, found);
6055
+ // Outra seleção chegou enquanto a pasta era lida: esta não vale mais.
6056
+ if (seq !== this.selectionSeq || !this.inputEl)
6057
+ return;
6058
+ found.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
6059
+ const transfer = new DataTransfer();
6060
+ for (const entry of found)
6061
+ transfer.items.add(entry.file);
6062
+ this.inputEl.files = transfer.files;
6063
+ this.droppedPaths = found.map((entry) => entry.path);
6064
+ this.publish();
6065
+ }
5795
6066
  setDragover(active) {
5796
6067
  if (this.hasAttribute("data-ark-dragover") === active)
5797
6068
  return;
@@ -5922,21 +6193,43 @@ class ArkFileInput extends HTMLElementBase {
5922
6193
  return `${(bytes / 1024).toFixed(1)} KB`;
5923
6194
  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
5924
6195
  }
5925
- // Lista dos nomes (com o tamanho) ou a string noFile.
6196
+ // Lista dos nomes (com o tamanho) ou a string noFile; por último, o aviso da pasta recusada. Em modo pasta a
6197
+ // seleção pode ter centenas de arquivos, então a lista é uma linha só: a pasta, a contagem e o tamanho total.
5926
6198
  syncList() {
5927
6199
  if (!this.listEl)
5928
6200
  return;
5929
6201
  const files = this.files;
6202
+ const locale = this.getLocale();
6203
+ const directory = this.directory;
5930
6204
  const text = this.getSizing().text;
5931
6205
  this.listEl.textContent = "";
6206
+ // max-w-full: centrada na zona, a lista teria a largura do nome mais longo e o truncate dos itens nunca cortaria.
5932
6207
  this.listEl.className = [
5933
- "ark:m-0 ark:flex ark:list-none ark:flex-col ark:items-center ark:gap-0.5 ark:p-0",
6208
+ "ark:m-0 ark:flex ark:max-w-full ark:list-none ark:flex-col ark:items-center ark:gap-0.5 ark:p-0",
5934
6209
  text
5935
6210
  ].join(" ");
5936
6211
  if (files.length === 0) {
5937
6212
  const item = document.createElement("li");
5938
6213
  item.className = "ark:text-fg-muted";
5939
- item.textContent = this.getLocale().noFile;
6214
+ item.textContent = directory ? locale.noFolder : locale.noFile;
6215
+ this.listEl.appendChild(item);
6216
+ }
6217
+ else if (directory) {
6218
+ const summary = this.summarize(locale);
6219
+ const item = document.createElement("li");
6220
+ item.setAttribute("data-ark-chrome", "summary");
6221
+ item.className = "ark:inline-flex ark:max-w-full ark:items-baseline ark:gap-1.5 ark:text-fg";
6222
+ if (summary.folder) {
6223
+ const name = document.createElement("span");
6224
+ name.className = "ark:truncate";
6225
+ name.textContent = summary.folder;
6226
+ item.appendChild(name);
6227
+ }
6228
+ const total = document.createElement("span");
6229
+ total.className = summary.folder ? "ark:shrink-0 ark:text-xs ark:text-fg-muted" : "ark:shrink-0";
6230
+ total.textContent = `${summary.count} · ${ArkFileInput.formatSize(summary.size)}`;
6231
+ item.appendChild(total);
6232
+ applyTestHooks(this, "file-input", item, "summary");
5940
6233
  this.listEl.appendChild(item);
5941
6234
  return;
5942
6235
  }
@@ -5954,6 +6247,13 @@ class ArkFileInput extends HTMLElementBase {
5954
6247
  applyTestHooks(this, "file-input", item, "item");
5955
6248
  this.listEl.appendChild(item);
5956
6249
  }
6250
+ if (this.folderRejected) {
6251
+ const item = document.createElement("li");
6252
+ item.className = "ark:text-danger-soft-fg";
6253
+ item.textContent = locale.foldersNotAccepted;
6254
+ applyTestHooks(this, "file-input", item, "rejected");
6255
+ this.listEl.appendChild(item);
6256
+ }
5957
6257
  }
5958
6258
  updateAppearance() {
5959
6259
  if (!this.inputEl ||
@@ -5970,10 +6270,14 @@ class ArkFileInput extends HTMLElementBase {
5970
6270
  const palette = this.getPalette(intent);
5971
6271
  const sizing = this.getSizing();
5972
6272
  const disabled = this.disabled;
6273
+ const directory = this.directory;
5973
6274
  const error = this.hasAttribute("error") || this.hasAttribute("error-message");
5974
6275
  const dragover = this.hasAttribute("data-ark-dragover");
5975
6276
  this.inputEl.name = this.getAttribute("name") || "";
5976
- this.inputEl.multiple = this.multiple;
6277
+ // Com `directory` o seletor abre em modo pasta. Onde o navegador não tem esse modo (mobile mais antigo) o atributo
6278
+ // não faz nada e sobra o seletor de arquivos: `multiple` deixa escolher os arquivos da pasta de uma vez.
6279
+ this.inputEl.multiple = this.multiple || directory;
6280
+ this.inputEl.toggleAttribute("webkitdirectory", directory);
5977
6281
  this.inputEl.required = this.hasAttribute("required");
5978
6282
  this.inputEl.disabled = disabled;
5979
6283
  const accept = this.getAttribute("accept");
@@ -6013,13 +6317,14 @@ class ArkFileInput extends HTMLElementBase {
6013
6317
  palette.ring
6014
6318
  ].join(" ");
6015
6319
  this.buttonEl.disabled = disabled;
6016
- if (this.buttonEl.getAttribute("data-ark-label") !== locale.chooseFile) {
6320
+ const choose = directory ? locale.chooseFolder : locale.chooseFile;
6321
+ if (this.buttonEl.getAttribute("data-ark-label") !== choose) {
6017
6322
  this.buttonEl.innerHTML = `${UPLOAD_SVG}<span></span>`;
6018
- this.buttonEl.lastElementChild.textContent = locale.chooseFile;
6019
- this.buttonEl.setAttribute("data-ark-label", locale.chooseFile);
6323
+ this.buttonEl.lastElementChild.textContent = choose;
6324
+ this.buttonEl.setAttribute("data-ark-label", choose);
6020
6325
  }
6021
6326
  this.hintEl.className = ["ark:text-fg-muted", sizing.text].join(" ");
6022
- this.hintEl.textContent = locale.dropHint;
6327
+ this.hintEl.textContent = directory ? locale.dropFolderHint : locale.dropHint;
6023
6328
  this.syncList();
6024
6329
  // Label: associação nativa com o input; o botão é nomeado pelo rótulo mais o próprio texto.
6025
6330
  const labelText = this.getAttribute("label") || "";
@@ -8206,7 +8511,7 @@ let nextId = 0;
8206
8511
  * silêncio e `change` dispara só no que ganhou a marca; as setas movem o foco
8207
8512
  * e marcam, Espaço marca o focado, e um único deles fica na ordem de Tab (o
8208
8513
  * marcado, ou o primeiro habilitado). `label`, aria-label e filhos nomeiam a
8209
- * opção como no ark-checkbox.
8514
+ * opção e `helper` a descreve, como no ark-checkbox.
8210
8515
  */
8211
8516
  class ArkRadio extends HTMLElementBase {
8212
8517
  static get observedAttributes() {
@@ -8216,6 +8521,7 @@ class ArkRadio extends HTMLElementBase {
8216
8521
  "name",
8217
8522
  "value",
8218
8523
  "label",
8524
+ "helper",
8219
8525
  "aria-label",
8220
8526
  "size",
8221
8527
  "intent",
@@ -8231,6 +8537,7 @@ class ArkRadio extends HTMLElementBase {
8231
8537
  this.boxEl = null;
8232
8538
  this.dotEl = null;
8233
8539
  this.labelEl = null;
8540
+ this.helperEl = null;
8234
8541
  this.inputEl = null;
8235
8542
  this.observer = null;
8236
8543
  /** Raiz do grupo no último connect, para ressincronizar os que ficam quando este sai. */
@@ -8451,11 +8758,11 @@ class ArkRadio extends HTMLElementBase {
8451
8758
  getSizing() {
8452
8759
  const size = (this.getAttribute("size") || "md").toLowerCase();
8453
8760
  const sizes = {
8454
- xs: { box: "ark:h-3.5 ark:w-3.5", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-xs" },
8455
- sm: { box: "ark:h-4 ark:w-4", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-sm" },
8456
- md: { box: "ark:h-5 ark:w-5", dot: "ark:h-2 ark:w-2", label: "ark:text-sm" },
8457
- lg: { box: "ark:h-6 ark:w-6", dot: "ark:h-2.5 ark:w-2.5", label: "ark:text-base" },
8458
- xl: { box: "ark:h-7 ark:w-7", dot: "ark:h-3 ark:w-3", label: "ark:text-lg" }
8761
+ xs: { box: "ark:h-3.5 ark:w-3.5", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-xs", helper: "ark:text-2xs" },
8762
+ sm: { box: "ark:h-4 ark:w-4", dot: "ark:h-1.5 ark:w-1.5", label: "ark:text-sm", helper: "ark:text-xs" },
8763
+ md: { box: "ark:h-5 ark:w-5", dot: "ark:h-2 ark:w-2", label: "ark:text-sm", helper: "ark:text-xs" },
8764
+ lg: { box: "ark:h-6 ark:w-6", dot: "ark:h-2.5 ark:w-2.5", label: "ark:text-base", helper: "ark:text-sm" },
8765
+ xl: { box: "ark:h-7 ark:w-7", dot: "ark:h-3 ark:w-3", label: "ark:text-lg", helper: "ark:text-base" }
8459
8766
  };
8460
8767
  return sizes[size] ?? sizes.md;
8461
8768
  }
@@ -8477,6 +8784,7 @@ class ArkRadio extends HTMLElementBase {
8477
8784
  input.tabIndex = -1;
8478
8785
  input.setAttribute("aria-hidden", "true");
8479
8786
  input.setAttribute("data-ark-chrome", "input");
8787
+ // A opção vem antes do input: um <label> do app em volta do host rotula o primeiro controle rotulável.
8480
8788
  this.prepend(box, input);
8481
8789
  this.boxEl = box;
8482
8790
  this.dotEl = dot;
@@ -8497,7 +8805,32 @@ class ArkRadio extends HTMLElementBase {
8497
8805
  }
8498
8806
  this.labelEl.htmlFor = this.boxEl?.id ?? "";
8499
8807
  this.labelEl.textContent = text;
8500
- this.labelEl.className = ["ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
8808
+ this.labelEl.className = ["ark:col-start-2 ark:cursor-[inherit] ark:select-none ark:text-fg", sizing.label].join(" ");
8809
+ }
8810
+ // Dica própria: um <span> depois do rótulo, só enquanto `helper` existir, que descreve a opção por aria-describedby.
8811
+ // Com ela o host vira grid (updateAppearance): a opção na primeira coluna, rótulo e dica empilhados na segunda.
8812
+ syncHelper(sizing) {
8813
+ if (!this.boxEl)
8814
+ return;
8815
+ const text = this.getAttribute("helper");
8816
+ if (!text) {
8817
+ this.helperEl?.remove();
8818
+ this.helperEl = null;
8819
+ this.boxEl.removeAttribute("aria-describedby");
8820
+ return;
8821
+ }
8822
+ if (!this.helperEl) {
8823
+ const helper = document.createElement("span");
8824
+ helper.setAttribute("data-ark-chrome", "helper");
8825
+ helper.id = `${this.boxEl.id}-helper`;
8826
+ (this.labelEl ?? this.inputEl)?.after(helper);
8827
+ this.helperEl = helper;
8828
+ }
8829
+ if (this.helperEl.textContent !== text)
8830
+ this.helperEl.textContent = text;
8831
+ // order: 1 põe a dica depois do rótulo livre do usuário, que vem depois dos nós próprios.
8832
+ this.helperEl.className = ["ark:col-start-2 ark:order-1 ark:text-fg-muted", sizing.helper].join(" ");
8833
+ this.boxEl.setAttribute("aria-describedby", this.helperEl.id);
8501
8834
  }
8502
8835
  syncName() {
8503
8836
  if (!this.boxEl)
@@ -8523,6 +8856,16 @@ class ArkRadio extends HTMLElementBase {
8523
8856
  this.boxEl.removeAttribute("aria-label");
8524
8857
  this.boxEl.removeAttribute("aria-labelledby");
8525
8858
  }
8859
+ // Nomeada pelo host, a dica entraria no nome: sai da árvore e segue como descrição (aria-describedby alcança
8860
+ // nós ocultos).
8861
+ if (this.helperEl) {
8862
+ if (this.boxEl.getAttribute("aria-labelledby") === this.id) {
8863
+ this.helperEl.setAttribute("aria-hidden", "true");
8864
+ }
8865
+ else {
8866
+ this.helperEl.removeAttribute("aria-hidden");
8867
+ }
8868
+ }
8526
8869
  }
8527
8870
  syncDot(checked, sizing) {
8528
8871
  if (!this.dotEl)
@@ -8558,9 +8901,18 @@ class ArkRadio extends HTMLElementBase {
8558
8901
  const sizing = this.getSizing();
8559
8902
  const checked = this.checked;
8560
8903
  const disabled = this.disabled;
8561
- this.applyOwnClasses("ark:inline-flex ark:cursor-pointer ark:items-center ark:gap-2 ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50".split(" "));
8904
+ // Com `helper` o host é grid: caixa na primeira coluna, rótulo e dica empilhados na segunda.
8905
+ const layout = this.hasAttribute("helper")
8906
+ ? "ark:inline-grid ark:grid-cols-[auto_minmax(0,1fr)] ark:gap-x-2 ark:gap-y-0.5"
8907
+ : "ark:inline-flex ark:gap-2";
8908
+ this.applyOwnClasses([
8909
+ layout,
8910
+ "ark:cursor-pointer ark:items-center ark:align-middle ark:has-disabled:cursor-not-allowed ark:has-disabled:opacity-50"
8911
+ ]
8912
+ .join(" ")
8913
+ .split(" "));
8562
8914
  this.boxEl.className = [
8563
- "ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-full ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
8915
+ "ark:col-start-1 ark:row-start-1 ark:inline-flex ark:shrink-0 ark:cursor-pointer ark:items-center ark:justify-center ark:rounded-full ark:border ark:outline-none ark:transition-colors ark:duration-(--ark-duration-quick) ark:ease-(--ark-ease-out) ark:focus-visible:ring-2 ark:focus-visible:ring-offset-2 ark:ring-offset-surface ark:disabled:cursor-not-allowed",
8564
8916
  palette.ring,
8565
8917
  sizing.box,
8566
8918
  checked ? palette.on : "ark:border-border-strong ark:bg-surface ark:text-transparent ark:hover:bg-surface-muted"
@@ -8569,6 +8921,7 @@ class ArkRadio extends HTMLElementBase {
8569
8921
  this.boxEl.disabled = disabled;
8570
8922
  this.syncDot(checked, sizing);
8571
8923
  this.syncLabel(sizing);
8924
+ this.syncHelper(sizing);
8572
8925
  this.syncName();
8573
8926
  this.inputEl.checked = checked;
8574
8927
  this.inputEl.disabled = disabled;
@@ -8579,6 +8932,8 @@ class ArkRadio extends HTMLElementBase {
8579
8932
  applyTestHooks(this, "radio", this.inputEl, "input");
8580
8933
  if (this.labelEl)
8581
8934
  applyTestHooks(this, "radio", this.labelEl, "label");
8935
+ if (this.helperEl)
8936
+ applyTestHooks(this, "radio", this.helperEl, "helper");
8582
8937
  }
8583
8938
  }
8584
8939
  ArkRadio.tagName = "ark-radio";