@iyulab/components 2.9.1 → 2.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.10.0] - 2026-10-07
4
+
5
+ ### Changed
6
+
7
+ - **Host roles and names are attributes, so role-based test queries find them.** `u-dialog`/`u-drawer` (`dialog`,
8
+ `aria-modal`, named by the `header` slot through `aria-labelledby`), `u-field` as a labelled `group`,
9
+ `u-progress-bar`/`u-progress-ring`/`u-spinner` (`progressbar` and `aria-valuenow`/`min`/`max`), `u-carousel`
10
+ (`region`, `aria-roledescription`) and the `u-tree-item` name were `ElementInternals` defaults. Those are invisible
11
+ from the DOM by design, so Playwright's `getByRole`, Testing Library and axe-core found no dialog, group, progress bar
12
+ or region — only the browser's accessibility tree had them. The accessibility tree is unchanged. An attribute is the
13
+ component's only if it was empty when first written; a `role` or `aria-*` you set — before or after — is never
14
+ overwritten or removed. A `header` element without an `id` gets one (`u-name-N`) so the dialog can reference it.
3
15
  ## [2.9.1] - 2026-10-07
4
16
 
5
17
  ### Fixed
@@ -1,4 +1,5 @@
1
1
  import { CSSResultGroup, PropertyValues } from 'lit';
2
+ import { HostAria } from '../utilities/hostAria.js';
2
3
  import { UElement } from './UElement.js';
3
4
  /** closeOn에 지정할 수 있는 닫기 트리거 */
4
5
  export type CloseOnPolicy = 'escape' | 'backdrop' | 'button';
@@ -42,19 +43,21 @@ export declare abstract class UOverlayElement extends UElement {
42
43
  */
43
44
  closeOn: CloseOnPolicy[];
44
45
  /**
45
- * 보조기기에 내놓는 역할 — 오버레이는 대화상자다(WAI-ARIA APG Dialog). 호스트 속성(`role`·`aria-label`·
46
- * `aria-labelledby`)이 있으면 그것이 이긴다 — 기본값만 여기서 정한다.
46
+ * 보조기기에 내놓는 역할 — 오버레이는 대화상자다(WAI-ARIA APG Dialog). 호스트 **속성**으로 단다 — `ElementInternals`
47
+ * 기본값은 DOM 에서 보이지 않아 Playwright `getByRole('dialog')`·axe 가 이 호스트를 찾지 못했다(`hostAria.ts`).
48
+ * 소비자가 단 `role`·`aria-label`·`aria-labelledby` 가 이긴다 — 우리 것은 비어 있던 자리뿐이다.
47
49
  */
48
- private internals?;
50
+ protected readonly aria: HostAria;
51
+ /** 이름으로 잇느라 머리 슬롯 요소에 우리가 준 id. */
52
+ private readonly nameIds;
49
53
  /** focus trap 인스턴스 (modal일 때만 사용) */
50
54
  private focusTrap?;
51
55
  /** modal이고 contained가 아닌 경우에만 body scroll lock */
52
56
  private get shouldLockBody();
53
- constructor();
54
57
  connectedCallback(): void;
55
58
  /**
56
59
  * 머리 슬롯에 놓인 것을 대화상자의 이름으로 삼는다 — 이름 없는 대화상자는 낭독기에 «대화상자» 라는 말만 남긴다.
57
- * 요소면 참조로 잇고(내용이 바뀌어도 따라간다), 글자 노드뿐이면 그 글자를 이름으로 둔다.
60
+ * 요소면 `aria-labelledby` 로 잇고(내용이 바뀌어도 따라간다), 글자 노드뿐이면 그 글자를 `aria-label` 로 둔다.
58
61
  */
59
62
  protected nameFromSlot(slot: HTMLSlotElement): void;
60
63
  disconnectedCallback(): void;
@@ -4,6 +4,7 @@ import __decorateMetadata from "../_virtual/_@oxc-project_runtime@0.152.0/helper
4
4
  import __decorate from "../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
5
5
  import { OverlayManager } from "../utilities/OverlayManager.js";
6
6
  import { arrayAttrConverter } from "../utilities/converters.js";
7
+ import { HostAria, nameFromSlot } from "../utilities/hostAria.js";
7
8
  import { styles } from "./UOverlayElement.styles.js";
8
9
  import { property } from "lit/decorators.js";
9
10
  import { createFocusTrap } from "focus-trap";
@@ -15,15 +16,8 @@ import { createFocusTrap } from "focus-trap";
15
16
  * @event hide - 오버레이가 숨겨지기 직전 발생합니다. 핸들러에서 취소하면 닫히지 않습니다.
16
17
  */
17
18
  var UOverlayElement = class extends UElement {
18
- static {
19
- this.styles = [super.styles, styles];
20
- }
21
- /** modal이고 contained가 아닌 경우에만 body scroll lock */
22
- get shouldLockBody() {
23
- return this.mode === "modal" && !this.contained;
24
- }
25
- constructor() {
26
- super();
19
+ constructor(..._args) {
20
+ super(..._args);
27
21
  this.open = false;
28
22
  this.contained = false;
29
23
  this.mode = "modal";
@@ -32,33 +26,30 @@ var UOverlayElement = class extends UElement {
32
26
  "backdrop",
33
27
  "button"
34
28
  ];
29
+ this.aria = new HostAria(this);
30
+ this.nameIds = /* @__PURE__ */ new Map();
35
31
  this.handlePointerdown = (e) => {
36
32
  if (e.composedPath()[0] === this) this.requestClose("backdrop");
37
33
  };
38
- if ("attachInternals" in this) {
39
- this.internals = this.attachInternals();
40
- this.internals.role = "dialog";
41
- }
34
+ }
35
+ static {
36
+ this.styles = [super.styles, styles];
37
+ }
38
+ /** modal이고 contained가 아닌 경우에만 body scroll lock */
39
+ get shouldLockBody() {
40
+ return this.mode === "modal" && !this.contained;
42
41
  }
43
42
  connectedCallback() {
44
43
  super.connectedCallback();
45
44
  this.setAttribute("tabindex", "-1");
45
+ this.aria.set("role", "dialog");
46
46
  }
47
47
  /**
48
48
  * 머리 슬롯에 놓인 것을 대화상자의 이름으로 삼는다 — 이름 없는 대화상자는 낭독기에 «대화상자» 라는 말만 남긴다.
49
- * 요소면 참조로 잇고(내용이 바뀌어도 따라간다), 글자 노드뿐이면 그 글자를 이름으로 둔다.
49
+ * 요소면 `aria-labelledby` 로 잇고(내용이 바뀌어도 따라간다), 글자 노드뿐이면 그 글자를 `aria-label` 로 둔다.
50
50
  */
51
51
  nameFromSlot(slot) {
52
- const internals = this.internals;
53
- if (!internals) return;
54
- const elements = slot.assignedElements({ flatten: true });
55
- if (elements.length > 0 && "ariaLabelledByElements" in internals) {
56
- internals.ariaLabelledByElements = elements;
57
- internals.ariaLabel = null;
58
- } else {
59
- if ("ariaLabelledByElements" in internals) internals.ariaLabelledByElements = null;
60
- internals.ariaLabel = slot.assignedNodes({ flatten: true }).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim() || null;
61
- }
52
+ nameFromSlot(this.aria, this, slot, this.nameIds);
62
53
  }
63
54
  disconnectedCallback() {
64
55
  this.cleanup();
@@ -66,7 +57,7 @@ var UOverlayElement = class extends UElement {
66
57
  }
67
58
  updated(changedProperties) {
68
59
  super.updated(changedProperties);
69
- if (changedProperties.has("mode") && this.internals) this.internals.ariaModal = this.mode === "modal" ? "true" : null;
60
+ if (changedProperties.has("mode")) this.aria.set("aria-modal", this.mode === "modal" ? "true" : null);
70
61
  if (changedProperties.has("open")) {
71
62
  if (this.open) this.setup();
72
63
  else this.cleanup();
@@ -51,8 +51,8 @@ export declare class UCarousel extends UElement {
51
51
  /** 포인터가 캐러셀 위에 있다 — 그동안만 잠시 멈춘다. */
52
52
  private hovered;
53
53
  private autoplayTimer?;
54
- /** 호스트 역할(region · «캐러셀» 역할 설명) — 소비자의 `role` 속성이 있으면 그것이 이긴다. */
55
- private readonly internals;
54
+ /** 호스트 역할(region · «캐러셀» 역할 설명)을 속성으로 — 소비자의 `role`·`aria-roledescription` 이 있으면 그것이 이긴다. */
55
+ private readonly aria;
56
56
  /** 지금 슬롯에 꽂힌 슬라이드와, 그중 우리가 단 속성(소비자가 단 것은 여기 없다 — 덮지도 회수하지도 않는다). */
57
57
  private slides;
58
58
  private readonly ownedSlideAttrs;
@@ -2,6 +2,7 @@ import { Locale } from "../../utilities/Locale.js";
2
2
  import { UElement } from "../UElement.js";
3
3
  import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
4
4
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
5
+ import { HostAria } from "../../utilities/hostAria.js";
5
6
  import "../button/UButton.js";
6
7
  import "../icon/UIcon.js";
7
8
  import { styles } from "./UCarousel.styles.js";
@@ -27,7 +28,7 @@ var UCarousel = class UCarousel extends UElement {
27
28
  this.dragOffset = 0;
28
29
  this.rotationStopped = false;
29
30
  this.hovered = false;
30
- this.internals = "attachInternals" in this ? this.attachInternals() : void 0;
31
+ this.aria = new HostAria(this);
31
32
  this.slides = [];
32
33
  this.ownedSlideAttrs = /* @__PURE__ */ new WeakMap();
33
34
  this.dragStartX = 0;
@@ -136,10 +137,8 @@ var UCarousel = class UCarousel extends UElement {
136
137
  }
137
138
  connectedCallback() {
138
139
  super.connectedCallback();
139
- if (this.internals) {
140
- this.internals.role = "region";
141
- this.internals.ariaRoleDescription = Locale.getValue("carousel");
142
- }
140
+ this.aria.set("role", "region");
141
+ this.aria.set("aria-roledescription", Locale.getValue("carousel"));
143
142
  this.addEventListener("focusin", this.handleFocusIn);
144
143
  this.addEventListener("pointerenter", this.handlePointerEnter);
145
144
  this.addEventListener("pointerleave", this.handlePointerLeave);
@@ -245,7 +244,7 @@ var UCarousel = class UCarousel extends UElement {
245
244
  }
246
245
  /** 렌더 밖에서 적어 둔 로케일 문장(호스트 역할 설명 · 슬라이드 이름)을 새 로케일로 다시 적는다. */
247
246
  localeChanged() {
248
- if (this.internals) this.internals.ariaRoleDescription = Locale.getValue("carousel");
247
+ if (this.isConnected) this.aria.set("aria-roledescription", Locale.getValue("carousel"));
249
248
  this.slides.forEach((slide, i) => this.labelSlide(slide, i, this.slides.length));
250
249
  super.localeChanged();
251
250
  }
@@ -65,8 +65,8 @@ export declare class UField extends UElement {
65
65
  * 버튼 둘을 «테마» 로 묶은 필드에서 첫 버튼의 이름이 «테마» 가 됐다 — 보이는 글자와 이름이 어긋난다(WCAG 2.5.3).
66
66
  */
67
67
  private get labelsAGroup();
68
- /** 묶음 이름(role=group)을 호스트에 — 섀도 밖 어떤 요소도 건드리지 않는다. */
69
- private readonly internals;
68
+ /** 묶음 이름(role=group)을 호스트 속성으로 — DOM 도구(`getByRole('group')`)도 본다. 소비자가 단 값이 이긴다. */
69
+ private readonly aria;
70
70
  /**
71
71
  * 🔴**«이 필드가 이름 줄 컨트롤을 가졌는가» 는 «지금 포커스 가능한가» 와 다른 질문이다 —
72
72
  * 그 둘을 한 술어로 답한 것이 결함이었다.**
@@ -1,6 +1,7 @@
1
1
  import { UElement } from "../UElement.js";
2
2
  import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
3
3
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
4
+ import { HostAria } from "../../utilities/hostAria.js";
4
5
  import { devWarnOnce } from "../../utilities/devWarning.js";
5
6
  import { styles } from "./UField.styles.js";
6
7
  import { html, nothing } from "lit";
@@ -40,7 +41,7 @@ var UField = class UField extends UElement {
40
41
  this.disabled = false;
41
42
  this.required = false;
42
43
  this.invalid = false;
43
- this.internals = "attachInternals" in this ? this.attachInternals() : void 0;
44
+ this.aria = new HostAria(this);
44
45
  this.handleLabelClick = () => {
45
46
  this.focus();
46
47
  };
@@ -183,10 +184,10 @@ var UField = class UField extends UElement {
183
184
  */
184
185
  nameSlottedControl() {
185
186
  const group = !!this.label && this.labelsAGroup;
186
- if (this.internals) {
187
- this.internals.role = group ? "group" : null;
188
- this.internals.ariaLabel = group ? this.label ?? null : null;
189
- this.internals.ariaDescription = group ? this.description ?? null : null;
187
+ if (this.isConnected) {
188
+ this.aria.set("role", group ? "group" : null);
189
+ this.aria.set("aria-label", group ? this.label ?? null : null);
190
+ this.aria.set("aria-description", group ? this.description ?? null : null);
190
191
  }
191
192
  if (group) {
192
193
  for (const c of this.nameCandidates) {
@@ -39,7 +39,7 @@ export declare class UProgressBar extends UElement {
39
39
  /** 현재값 */
40
40
  value: number;
41
41
  /** 보조기기에 내놓는 역할·값(`progressbar`) — 호스트 속성이 이긴다. */
42
- private readonly internals;
42
+ private readonly aria;
43
43
  private progress;
44
44
  private bufferProgress;
45
45
  protected willUpdate(changedProperties: PropertyValues): void;
@@ -1,7 +1,8 @@
1
1
  import { UElement } from "../UElement.js";
2
2
  import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
3
3
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
4
- import { attachProgressbar, syncProgressValue } from "../../utilities/progressAria.js";
4
+ import { HostAria } from "../../utilities/hostAria.js";
5
+ import { syncProgressbar } from "../../utilities/progressAria.js";
5
6
  import { styles } from "./UProgressBar.styles.js";
6
7
  import { html } from "lit";
7
8
  import { customElement, property, state } from "lit/decorators.js";
@@ -18,7 +19,7 @@ var UProgressBar = class UProgressBar extends UElement {
18
19
  this.min = 0;
19
20
  this.max = 100;
20
21
  this.value = 0;
21
- this.internals = attachProgressbar(this);
22
+ this.aria = new HostAria(this);
22
23
  this.progress = 0;
23
24
  this.bufferProgress = 0;
24
25
  }
@@ -44,7 +45,7 @@ var UProgressBar = class UProgressBar extends UElement {
44
45
  "max",
45
46
  "value",
46
47
  "indeterminate"
47
- ].some((k) => changedProperties.has(k))) syncProgressValue(this.internals, this);
48
+ ].some((k) => changedProperties.has(k))) syncProgressbar(this.aria, this);
48
49
  }
49
50
  render() {
50
51
  const hasBuffer = this.buffer !== void 0 && !this.indeterminate;
@@ -36,7 +36,7 @@ export declare class UProgressRing extends UElement {
36
36
  /** 현재값 */
37
37
  value: number;
38
38
  /** 보조기기에 내놓는 역할·값(`progressbar`) — 호스트 속성이 이긴다. */
39
- private readonly internals;
39
+ private readonly aria;
40
40
  private progress;
41
41
  private bufferProgress;
42
42
  private dasharray;
@@ -1,7 +1,8 @@
1
1
  import { UElement } from "../UElement.js";
2
2
  import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
3
3
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
4
- import { attachProgressbar, syncProgressValue } from "../../utilities/progressAria.js";
4
+ import { HostAria } from "../../utilities/hostAria.js";
5
+ import { syncProgressbar } from "../../utilities/progressAria.js";
5
6
  import { styles } from "./UProgressRing.styles.js";
6
7
  import { html } from "lit";
7
8
  import { customElement, property, state } from "lit/decorators.js";
@@ -19,7 +20,7 @@ var UProgressRing = class UProgressRing extends UElement {
19
20
  this.min = 0;
20
21
  this.max = 100;
21
22
  this.value = 0;
22
- this.internals = attachProgressbar(this);
23
+ this.aria = new HostAria(this);
23
24
  this.progress = 0;
24
25
  this.bufferProgress = 0;
25
26
  this.dasharray = PATH_LENGTH.toString();
@@ -48,7 +49,7 @@ var UProgressRing = class UProgressRing extends UElement {
48
49
  "max",
49
50
  "value",
50
51
  "indeterminate"
51
- ].some((k) => changedProperties.has(k))) syncProgressValue(this.internals, this);
52
+ ].some((k) => changedProperties.has(k))) syncProgressbar(this.aria, this);
52
53
  }
53
54
  render() {
54
55
  const hasBuffer = this.buffer !== void 0 && !this.indeterminate;
@@ -23,7 +23,7 @@ export declare class USpinner extends UElement {
23
23
  * 보조기기에는 «양을 모르는 진행»(`progressbar`, 값 없음). 이름은 슬롯 글자, 없으면 로케일의 `loading` — 회전하는
24
24
  * 그림만으로는 무엇이 진행 중인지 들리지 않는다. 호스트의 `aria-label` 이 이긴다.
25
25
  */
26
- private readonly internals;
26
+ private readonly aria;
27
27
  connectedCallback(): void;
28
28
  /** 이름으로 쓰는 보이는 글자(없으면 로케일의 «로딩 중»). */
29
29
  private slotText;
@@ -2,8 +2,9 @@ import { Locale } from "../../utilities/Locale.js";
2
2
  import { UElement } from "../UElement.js";
3
3
  import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
4
4
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
5
+ import { HostAria } from "../../utilities/hostAria.js";
5
6
  import { styles } from "./USpinner.styles.js";
6
- import { attachProgressbar } from "../../utilities/progressAria.js";
7
+ import { syncProgressbar } from "../../utilities/progressAria.js";
7
8
  import { html } from "lit";
8
9
  import { customElement, property, state } from "lit/decorators.js";
9
10
  //#region src/components/spinner/USpinner.ts
@@ -11,7 +12,7 @@ var USpinner = class USpinner extends UElement {
11
12
  constructor(..._args) {
12
13
  super(..._args);
13
14
  this.hasLabel = false;
14
- this.internals = attachProgressbar(this);
15
+ this.aria = new HostAria(this);
15
16
  this.slotText = "";
16
17
  }
17
18
  static {
@@ -23,7 +24,9 @@ var USpinner = class USpinner extends UElement {
23
24
  }
24
25
  nameFrom(text) {
25
26
  this.slotText = text;
26
- if (this.internals) this.internals.ariaLabel = text || Locale.getValue("loading");
27
+ if (!this.isConnected) return;
28
+ syncProgressbar(this.aria);
29
+ this.aria.set("aria-label", text || Locale.getValue("loading"));
27
30
  }
28
31
  /** 글자가 없을 때의 기본 이름은 로케일 문장이다 — 새 로케일로 다시 적는다. */
29
32
  localeChanged() {
@@ -53,9 +53,10 @@ export declare class UTreeItem extends UElement {
53
53
  get childItems(): readonly UTreeItem[];
54
54
  /**
55
55
  * 이름 = 자기 라벨(기본 슬롯)의 글자. 역할이 호스트에 있으므로 내용에서 이름을 계산하면 **자식 항목의 글자까지**
56
- * 들어갔다(실측: 부모 이름 «Root Child»). 호스트의 `aria-label` 이 이긴다.
56
+ * 들어갔다(실측: 부모 이름 «Root Child»). 속성으로 단다(DOM 도구의 `getByRole('treeitem', { name })` 도 본다) —
57
+ * 소비자가 단 `aria-label` 이 이긴다.
57
58
  */
58
- private readonly internals;
59
+ private readonly aria;
59
60
  connectedCallback(): void;
60
61
  protected updated(changedProperties: PropertyValues): void;
61
62
  render(): import('lit-html').TemplateResult<1>;
@@ -1,6 +1,7 @@
1
1
  import { UElement } from "../UElement.js";
2
2
  import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
3
3
  import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
4
+ import { HostAria } from "../../utilities/hostAria.js";
4
5
  import "../spinner/USpinner.js";
5
6
  import "../icon/UIcon.js";
6
7
  import { isFromNestedControl } from "../../utilities/nestedControl.js";
@@ -30,15 +31,13 @@ var UTreeItem = class UTreeItem extends UElement {
30
31
  this.indeterminate = false;
31
32
  this._parentItem = null;
32
33
  this._childItems = [];
33
- this.internals = "attachInternals" in this ? this.attachInternals() : void 0;
34
+ this.aria = new HostAria(this);
34
35
  this.handleSlotChange = (e) => {
35
36
  const slot = e.target;
36
37
  const elements = slot.assignedElements({ flatten: true });
37
38
  for (const el of elements) if (el instanceof _UTreeItem && !el.hasAttribute("slot")) el.setAttribute("slot", "children");
38
- if (this.internals) {
39
- const text = slot.assignedNodes({ flatten: true }).filter((n) => !(n instanceof _UTreeItem)).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim();
40
- this.internals.ariaLabel = text || null;
41
- }
39
+ const text = slot.assignedNodes({ flatten: true }).filter((n) => !(n instanceof _UTreeItem)).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim();
40
+ this.aria.set("aria-label", text || null);
42
41
  };
43
42
  this.handleChildrenSlotChange = (e) => {
44
43
  const slot = e.target;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * A component's own ARIA on its host, written as attributes — and only where the author left them empty.
3
+ *
4
+ * `ElementInternals` defaults are invisible from the DOM by design, so every DOM-based tool — Playwright's
5
+ * `getByRole`, Testing Library's `*ByRole`, axe-core — computes a host with no role and no name, while the
6
+ * browser's accessibility tree shows both. A role-based e2e query then finds nothing, and an audit of a `dialog`
7
+ * named only through internals would report it unnamed. An attribute is what assistive technology and those
8
+ * tools both read.
9
+ *
10
+ * Ownership rule: an attribute is ours only if it was absent the first time we wrote it, and it stays ours only
11
+ * while it still holds the value we last wrote. An author value — set before or after — always wins: we never
12
+ * overwrite it and never remove it. Attributes cannot be written from a custom element constructor, so the first
13
+ * write belongs in `connectedCallback` or later.
14
+ */
15
+ export declare class HostAria {
16
+ private readonly host;
17
+ /** attribute → the value we last wrote (`null` = we removed it, or wrote nothing yet). */
18
+ private readonly owned;
19
+ /** Attributes the author set — never touched again. */
20
+ private readonly authored;
21
+ constructor(host: Element);
22
+ /** Writes `value` (`null` removes) if the attribute is ours. Returns whether it is. */
23
+ set(name: string, value: string | null): boolean;
24
+ /** True when the author has set this attribute — the host's own value, not ours. */
25
+ isAuthored(name: string): boolean;
26
+ /**
27
+ * Decides ownership. A first look at an empty attribute makes it ours (when `take`); a value we did not write
28
+ * makes it the author's for good.
29
+ */
30
+ private claim;
31
+ }
32
+ /**
33
+ * Names `host` after the elements (or text) of one of its slots, as `aria-labelledby` — or `aria-label` when the
34
+ * slot holds only text, or elements outside the host's tree that an IDREF cannot reach. An author's
35
+ * `aria-label`/`aria-labelledby` on the host wins over both. Ids we give to slotted elements are tracked in
36
+ * `given` and withdrawn once those elements leave the slot (unless the author has since changed them).
37
+ */
38
+ export declare function nameFromSlot(aria: HostAria, host: Element, slot: HTMLSlotElement, given: Map<Element, string>): void;
@@ -0,0 +1,88 @@
1
+ //#region src/utilities/hostAria.ts
2
+ /**
3
+ * A component's own ARIA on its host, written as attributes — and only where the author left them empty.
4
+ *
5
+ * `ElementInternals` defaults are invisible from the DOM by design, so every DOM-based tool — Playwright's
6
+ * `getByRole`, Testing Library's `*ByRole`, axe-core — computes a host with no role and no name, while the
7
+ * browser's accessibility tree shows both. A role-based e2e query then finds nothing, and an audit of a `dialog`
8
+ * named only through internals would report it unnamed. An attribute is what assistive technology and those
9
+ * tools both read.
10
+ *
11
+ * Ownership rule: an attribute is ours only if it was absent the first time we wrote it, and it stays ours only
12
+ * while it still holds the value we last wrote. An author value — set before or after — always wins: we never
13
+ * overwrite it and never remove it. Attributes cannot be written from a custom element constructor, so the first
14
+ * write belongs in `connectedCallback` or later.
15
+ */
16
+ var HostAria = class {
17
+ constructor(host) {
18
+ this.host = host;
19
+ this.owned = /* @__PURE__ */ new Map();
20
+ this.authored = /* @__PURE__ */ new Set();
21
+ }
22
+ /** Writes `value` (`null` removes) if the attribute is ours. Returns whether it is. */
23
+ set(name, value) {
24
+ if (!this.claim(name)) return false;
25
+ if (value === null) this.host.removeAttribute(name);
26
+ else if (this.host.getAttribute(name) !== value) this.host.setAttribute(name, value);
27
+ this.owned.set(name, value);
28
+ return true;
29
+ }
30
+ /** True when the author has set this attribute — the host's own value, not ours. */
31
+ isAuthored(name) {
32
+ return !this.claim(name, false);
33
+ }
34
+ /**
35
+ * Decides ownership. A first look at an empty attribute makes it ours (when `take`); a value we did not write
36
+ * makes it the author's for good.
37
+ */
38
+ claim(name, take = true) {
39
+ if (this.authored.has(name)) return false;
40
+ const current = this.host.getAttribute(name);
41
+ if (this.owned.has(name)) {
42
+ if (current === this.owned.get(name)) return true;
43
+ this.owned.delete(name);
44
+ this.authored.add(name);
45
+ return false;
46
+ }
47
+ if (current !== null) {
48
+ this.authored.add(name);
49
+ return false;
50
+ }
51
+ if (take) this.owned.set(name, null);
52
+ return true;
53
+ }
54
+ };
55
+ var nextId = 0;
56
+ /**
57
+ * Names `host` after the elements (or text) of one of its slots, as `aria-labelledby` — or `aria-label` when the
58
+ * slot holds only text, or elements outside the host's tree that an IDREF cannot reach. An author's
59
+ * `aria-label`/`aria-labelledby` on the host wins over both. Ids we give to slotted elements are tracked in
60
+ * `given` and withdrawn once those elements leave the slot (unless the author has since changed them).
61
+ */
62
+ function nameFromSlot(aria, host, slot, given) {
63
+ const authorNamed = aria.isAuthored("aria-label") || aria.isAuthored("aria-labelledby");
64
+ const elements = slot.assignedElements({ flatten: true });
65
+ const sameTree = elements.length > 0 && elements.every((el) => el.getRootNode() === host.getRootNode());
66
+ for (const [el, id] of [...given]) if (!elements.includes(el)) {
67
+ if (el.id === id) el.removeAttribute("id");
68
+ given.delete(el);
69
+ }
70
+ if (authorNamed) return;
71
+ if (sameTree) {
72
+ const ids = elements.map((el) => {
73
+ if (!el.id) {
74
+ el.id = `u-name-${++nextId}`;
75
+ given.set(el, el.id);
76
+ }
77
+ return el.id;
78
+ });
79
+ aria.set("aria-label", null);
80
+ aria.set("aria-labelledby", ids.join(" "));
81
+ } else {
82
+ const text = slot.assignedNodes({ flatten: true }).map((n) => n.textContent ?? "").join(" ").replace(/\s+/g, " ").trim();
83
+ aria.set("aria-labelledby", null);
84
+ aria.set("aria-label", text || null);
85
+ }
86
+ }
87
+ //#endregion
88
+ export { HostAria, nameFromSlot };
@@ -1,12 +1,13 @@
1
+ import { HostAria } from './hostAria.js';
1
2
  /**
2
3
  * 진행 표시(`u-progress-bar`·`u-progress-ring`·`u-spinner`)를 보조기기에 `progressbar` 로 내놓는다.
3
4
  *
4
5
  * 그리는 막대·고리만 있고 역할이 없으면 보조기기에는 아무것도 없다 — 진행 중이라는 사실도, 몇 % 인지도.
5
- * 역할과 값은 `ElementInternals` 기본값이라 호스트에 단 `role`·`aria-*` 속성이 이긴다. 값이 정해지지 않은
6
- * 진행(`indeterminate`·스피너)은 `aria-valuenow` 를 두지 않는다 — WAI-ARIA 의 «진행 중, 양은 모름» 표기.
6
+ * 역할과 값은 호스트 **속성**이다(`HostAria` — DOM 도구도 보도록) · 소비자가 단 `role`·`aria-*` 가 이긴다.
7
+ * 값이 정해지지 않은 진행(`indeterminate`·스피너)은 `aria-valuenow` 를 두지 않는다 — WAI-ARIA 의 «진행 중, 양은 모름» 표기.
8
+ * 값을 주지 않으면(스피너) 역할만 단다.
7
9
  */
8
- export declare function attachProgressbar(host: HTMLElement): ElementInternals | undefined;
9
- export declare function syncProgressValue(internals: ElementInternals | undefined, state: {
10
+ export declare function syncProgressbar(aria: HostAria, state?: {
10
11
  indeterminate: boolean;
11
12
  value: number;
12
13
  min: number;
@@ -3,20 +3,16 @@
3
3
  * 진행 표시(`u-progress-bar`·`u-progress-ring`·`u-spinner`)를 보조기기에 `progressbar` 로 내놓는다.
4
4
  *
5
5
  * 그리는 막대·고리만 있고 역할이 없으면 보조기기에는 아무것도 없다 — 진행 중이라는 사실도, 몇 % 인지도.
6
- * 역할과 값은 `ElementInternals` 기본값이라 호스트에 단 `role`·`aria-*` 속성이 이긴다. 값이 정해지지 않은
7
- * 진행(`indeterminate`·스피너)은 `aria-valuenow` 를 두지 않는다 — WAI-ARIA 의 «진행 중, 양은 모름» 표기.
6
+ * 역할과 값은 호스트 **속성**이다(`HostAria` — DOM 도구도 보도록) · 소비자가 단 `role`·`aria-*` 가 이긴다.
7
+ * 값이 정해지지 않은 진행(`indeterminate`·스피너)은 `aria-valuenow` 를 두지 않는다 — WAI-ARIA 의 «진행 중, 양은 모름» 표기.
8
+ * 값을 주지 않으면(스피너) 역할만 단다.
8
9
  */
9
- function attachProgressbar(host) {
10
- if (!("attachInternals" in host)) return void 0;
11
- const internals = host.attachInternals();
12
- internals.role = "progressbar";
13
- return internals;
14
- }
15
- function syncProgressValue(internals, state) {
16
- if (!internals) return;
17
- internals.ariaValueMin = String(state.min);
18
- internals.ariaValueMax = String(state.max);
19
- internals.ariaValueNow = state.indeterminate ? null : String(Math.max(state.min, Math.min(state.max, state.value)));
10
+ function syncProgressbar(aria, state) {
11
+ aria.set("role", "progressbar");
12
+ if (!state) return;
13
+ aria.set("aria-valuemin", String(state.min));
14
+ aria.set("aria-valuemax", String(state.max));
15
+ aria.set("aria-valuenow", state.indeterminate ? null : String(Math.max(state.min, Math.min(state.max, state.value))));
20
16
  }
21
17
  //#endregion
22
- export { attachProgressbar, syncProgressValue };
18
+ export { syncProgressbar };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "2.9.1",
4
+ "version": "2.10.0",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -85,6 +85,14 @@ carries the control's role, not on the host element. Native nodes use native `di
85
85
  `u-radio`/`u-rating`, the `slider` thumbs). In end-to-end tests, locate controls by role
86
86
  (`getByRole('combobox')`) rather than by tag, so actionability checks see the disabled state.
87
87
 
88
+ **Roles that belong to the host are host attributes**, so DOM-based role queries (Playwright, Testing
89
+ Library) and axe-core see what assistive technology sees: `u-dialog`/`u-drawer` are `dialog` named by
90
+ their `header` slot (`Dialog.alert`/`confirm` are `alertdialog`), `u-field` over several controls is a
91
+ `group` named by its label, `u-progress-bar`/`u-progress-ring`/`u-spinner` are `progressbar` with
92
+ `aria-value*`, `u-carousel` is a `region`, and `u-tree-item` is named by its own label. Write
93
+ `getByRole('dialog', { name: 'Delete item' })` — not a tag selector. A `role` or `aria-*` attribute you
94
+ set on the host yourself always wins and is never overwritten.
95
+
88
96
  ### Overlay & Floating
89
97
 
90
98
  - [`u-dialog`](./references/components/dialog.md) — Modal/non-modal dialog with configurable placement