@iyulab/components 2.3.1 → 2.4.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,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.4.0] - 2026-10-06
4
+
5
+ ### Fixed
6
+
7
+ - **`u-dialog` and `u-drawer` are exposed as dialogs.** They trapped focus but carried no role, so a screen reader user
8
+ landed among unfamiliar buttons without hearing that anything had opened, and `getByRole('dialog')` found nothing.
9
+ The host is now a `dialog` (via `ElementInternals`), with `aria-modal` when `mode="modal"`, named by the `header` slot
10
+ (tracking its content). `aria-label`, `aria-labelledby` and `role` on the host still override.
11
+ - **`Dialog.alert` and `Dialog.confirm` open as an `alertdialog`**, like a native `confirm()` — moving from `confirm()`
12
+ to `Dialog.confirm` no longer loses that. With a `title` the title names the dialog and the message describes it;
13
+ without one the message is the name. `Dialog.prompt` and `Dialog.show` are named the same way, as a `dialog`.
14
+ - **`u-switch` is exposed as a `switch`**, not a checkbox — announced as on/off, and found by `getByRole('switch')`.
15
+ - **`u-file-input`: setting `value` to `null` (or `[]`) clears the native input**, as `reset()` did. It only synced the
16
+ form value, so after an app reset the state the native input still held the last file — picking that same file again
17
+ fired no `change`, and nothing happened.
18
+ - **`u-input` keeps a minimum text area.** The suffix icons (number stepper, clear, password toggle) have a fixed box —
19
+ at least 24px, or `--u-target-size` — and in a narrow field they took the whole width: a 90px number input drew a 0px
20
+ text area, with no value or caret visible. The field now has a floor (`--input-min-text`, default `4ch`, plus the
21
+ icons it shows); given less, it overflows its host visibly. Fields at their default or a wider width are unchanged.
22
+
3
23
  ## [2.3.1] - 2026-10-06
4
24
 
5
25
  ### Fixed
@@ -41,11 +41,22 @@ export declare abstract class UOverlayElement extends UElement {
41
41
  * ['escape', 'backdrop', 'button']
42
42
  */
43
43
  closeOn: CloseOnPolicy[];
44
+ /**
45
+ * 보조기기에 내놓는 역할 — 오버레이는 대화상자다(WAI-ARIA APG Dialog). 호스트 속성(`role`·`aria-label`·
46
+ * `aria-labelledby`)이 있으면 그것이 이긴다 — 기본값만 여기서 정한다.
47
+ */
48
+ private internals?;
44
49
  /** focus trap 인스턴스 (modal일 때만 사용) */
45
50
  private focusTrap?;
46
51
  /** modal이고 contained가 아닌 경우에만 body scroll lock */
47
52
  private get shouldLockBody();
53
+ constructor();
48
54
  connectedCallback(): void;
55
+ /**
56
+ * 머리 슬롯에 놓인 것을 대화상자의 이름으로 삼는다 — 이름 없는 대화상자는 낭독기에 «대화상자» 라는 말만 남긴다.
57
+ * 요소면 참조로 잇고(내용이 바뀌어도 따라간다), 글자 노드뿐이면 그 글자를 이름으로 둔다.
58
+ */
59
+ protected nameFromSlot(slot: HTMLSlotElement): void;
49
60
  disconnectedCallback(): void;
50
61
  protected updated(changedProperties: PropertyValues): void;
51
62
  /**
@@ -15,8 +15,15 @@ import { createFocusTrap } from "focus-trap";
15
15
  * @event hide - 오버레이가 숨겨지기 직전 발생합니다. 핸들러에서 취소하면 닫히지 않습니다.
16
16
  */
17
17
  var UOverlayElement = class extends UElement {
18
- constructor(..._args) {
19
- super(..._args);
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();
20
27
  this.open = false;
21
28
  this.contained = false;
22
29
  this.mode = "modal";
@@ -28,24 +35,38 @@ var UOverlayElement = class extends UElement {
28
35
  this.handlePointerdown = (e) => {
29
36
  if (e.composedPath()[0] === this) this.requestClose("backdrop");
30
37
  };
31
- }
32
- static {
33
- this.styles = [super.styles, styles];
34
- }
35
- /** modal이고 contained가 아닌 경우에만 body scroll lock */
36
- get shouldLockBody() {
37
- return this.mode === "modal" && !this.contained;
38
+ if ("attachInternals" in this) {
39
+ this.internals = this.attachInternals();
40
+ this.internals.role = "dialog";
41
+ }
38
42
  }
39
43
  connectedCallback() {
40
44
  super.connectedCallback();
41
45
  this.setAttribute("tabindex", "-1");
42
46
  }
47
+ /**
48
+ * 머리 슬롯에 놓인 것을 대화상자의 이름으로 삼는다 — 이름 없는 대화상자는 낭독기에 «대화상자» 라는 말만 남긴다.
49
+ * 요소면 참조로 잇고(내용이 바뀌어도 따라간다), 글자 노드뿐이면 그 글자를 이름으로 둔다.
50
+ */
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
+ }
62
+ }
43
63
  disconnectedCallback() {
44
64
  this.cleanup();
45
65
  super.disconnectedCallback();
46
66
  }
47
67
  updated(changedProperties) {
48
68
  super.updated(changedProperties);
69
+ if (changedProperties.has("mode") && this.internals) this.internals.ariaModal = this.mode === "modal" ? "true" : null;
49
70
  if (changedProperties.has("open")) {
50
71
  if (this.open) this.setup();
51
72
  else this.cleanup();
@@ -50,6 +50,7 @@ var UDialog = class UDialog extends UOverlayElement {
50
50
  handleHeaderSlotChange(e) {
51
51
  const slot = e.target;
52
52
  this.hasHeader = slot.assignedNodes({ flatten: true }).length > 0;
53
+ this.nameFromSlot(slot);
53
54
  }
54
55
  };
55
56
  __decorate([property({
@@ -42,6 +42,7 @@ var UDrawer = class UDrawer extends UOverlayElement {
42
42
  handleHeaderSlotChange(e) {
43
43
  const slot = e.target;
44
44
  this.hasHeader = slot.assignedNodes({ flatten: true }).length > 0;
45
+ this.nameFromSlot(slot);
45
46
  }
46
47
  };
47
48
  __decorate([property({
@@ -53,7 +53,10 @@ var UFileInput = class UFileInput extends UFormControlElement {
53
53
  * 넘긴다 — 네이티브 `<input type="file" multiple>`의 제출 형태와 동일하다. */
54
54
  updated(changedProperties) {
55
55
  super.updated(changedProperties);
56
- if (changedProperties.has("value")) this.syncFormValue();
56
+ if (changedProperties.has("value")) {
57
+ this.syncFormValue();
58
+ if ((!this.value || this.value.length === 0) && this.inputEl?.value) this.inputEl.value = "";
59
+ }
57
60
  }
58
61
  syncFormValue() {
59
62
  const files = this.value ?? [];
@@ -40,6 +40,8 @@ export type FieldSize = 'sm' | 'md' | 'lg';
40
40
  * 컨테이너 폭을 채우려면 `block`으로 지정한다.
41
41
  * @cssprop --u-input-width - 호스트의 width (기본값: auto). flex 컨테이너처럼 block만으로는
42
42
  * 늘어나지 않는 맥락에서 `100%`로 지정한다.
43
+ * @cssprop --input-min-text - 글자 영역의 최소 폭 (기본값: 4ch). 접미 아이콘(스테퍼·지우기·비밀번호 토글)이 폭을 나눠도 글자
44
+ * 영역은 이 아래로 접히지 않는다 — 주어진 폭이 그보다 좁으면 칸이 호스트 밖으로 넘친다.
43
45
  * @cssprop --input-popover-width - 드롭다운 팝오버의 너비 (기본값: 앵커(트리거) 너비)
44
46
  * @cssprop --input-popover-min-height - 드롭다운 팝오버의 최소 높이 (기본값: 0px)
45
47
  * @cssprop --input-popover-max-height - 드롭다운 팝오버의 최대 높이 (기본값: 50vh)
@@ -193,7 +193,8 @@ var UInput = class UInput extends UFormControlElement {
193
193
  .description=${this.description}
194
194
  .validationMessage=${this.validationMessage}
195
195
  >
196
- <div class="container" part="container">
196
+ <div class="container" part="container"
197
+ style=${`--_icons: ${(showStepper ? 2 : 0) + (showClear ? 1 : 0) + (showToggle ? 1 : 0)}`}>
197
198
 
198
199
  <slot name="prefix"></slot>
199
200
 
@@ -35,6 +35,17 @@ var styles = css`
35
35
  테두리 1px 위까지 닿는다. 패딩 상자에서 자르면 그 1px 이 눌리지 않는다(hidden 은 여백을 받지 않는다). */
36
36
  overflow: clip;
37
37
  overflow-clip-margin: 1px;
38
+ /* 글자 영역의 하한 — 고정 크기 접미 아이콘(스테퍼 둘 · 지우기 · 비밀번호 토글, 각 상자 = max(1.5em, 24px, 호스트 하한))이
39
+ 한 줄을 나눌 때, 주어진 폭이 좁으면 입력이 0 까지 접혀 값도 커서도 «보이지 않는» 채 정상처럼 그려졌다.
40
+ 하한 아래로는 칸이 호스트 밖으로 넘친다 — 보이는 실패다. 아이콘 수(--_icons)는 렌더가 정한다.
41
+ 입력의 고유 폭(size 기본 20자)이 intrinsic 계산을 지배하므로 min-content 로는 낼 수 없어 기하를 직접 더한다.
42
+ 접두·접미 슬롯 내용은 세지 않는다(폭을 모른다). 글자 하한은 --input-min-text 로 바꾼다. */
43
+ --_icon-box: max(1.5em, 24px, var(--u-target-size, 0px));
44
+ min-inline-size: calc(
45
+ 2px + var(--u-field-padding-inline, 0.6em) + var(--input-min-text, 4ch)
46
+ + var(--_icons, 0) * var(--_icon-box)
47
+ + max(var(--u-field-padding-inline, 0.6em), calc(var(--u-target-size, 0px) / 2 - 0.5em))
48
+ );
38
49
  }
39
50
  :host([readonly]) .container,
40
51
  :host(:disabled) .container {
@@ -47,6 +47,7 @@ var USwitch = class USwitch extends UFormControlElement {
47
47
  <label class="wrapper" part="wrapper">
48
48
  <input
49
49
  type="checkbox"
50
+ role="switch"
50
51
  aria-label=${ifDefined(this.contentAriaLabel)}
51
52
  ?disabled=${this.effectivelyDisabled || this.readonly}
52
53
  ?required=${this.required}
@@ -88,6 +88,8 @@ export declare class Dialog {
88
88
  * @returns 클릭된 액션의 value 또는 닫힌 경우 null
89
89
  */
90
90
  static show(options: CustomDialogOptions): Promise<string | null>;
91
+ /** `show` 의 본체 — `decorate` 는 `alert`·`confirm`·`prompt` 가 렌더 뒤 접근성 이름·설명을 잇는 자리다. */
92
+ private static present;
91
93
  /** 다이얼로그 엘리먼트를 생성하고 옵션을 적용합니다. */
92
94
  private static createDialog;
93
95
  }
@@ -10,9 +10,23 @@ import { unsafeHTML } from "lit/directives/unsafe-html.js";
10
10
  /**
11
11
  * 메시지를 본문 템플릿으로 — 문자열은 lit 이 글자로 이스케이프한다. `show` 는 문자열 `content` 를 HTML 로 해석하므로
12
12
  * (그것이 `show` 의 계약이다) `alert`·`confirm` 이 문자열을 그대로 넘기면 그 계약을 조용히 물려받아 마크업 주입 싱크가 된다.
13
+ *
14
+ * 메시지 상자에는 id 를 준다 — 대화상자의 이름(제목이 없을 때)이나 설명(제목이 있을 때)으로 잇는다.
13
15
  */
14
- function asText(message) {
15
- return html`${message}`;
16
+ function asText(message, id) {
17
+ return html`<div id=${id}>${message}</div>`;
18
+ }
19
+ var messageSeq = 0;
20
+ var nextMessageId = () => `u-dialog-message-${++messageSeq}`;
21
+ /**
22
+ * 보조기기가 듣는 대화상자의 이름과 설명 — 제목이 있으면 제목이 이름이고 메시지가 설명이다(APG Alert Dialog).
23
+ * 제목이 없으면 메시지가 이름이다 — 이름 없는 대화상자는 «대화상자» 라는 말만 남긴다.
24
+ */
25
+ function describe(dialog, messageId, role) {
26
+ if (role === "alertdialog") dialog.setAttribute("role", "alertdialog");
27
+ const titleId = dialog.querySelector(":scope > [slot=\"header\"]")?.id;
28
+ dialog.setAttribute("aria-labelledby", titleId || messageId);
29
+ if (titleId) dialog.setAttribute("aria-describedby", messageId);
16
30
  }
17
31
  /**
18
32
  * Dialog 유틸리티 클래스입니다.
@@ -27,10 +41,11 @@ var Dialog = class {
27
41
  * `TemplateResult`(`html\`…\``)를 넘긴다. HTML 문자열은 그것을 명시한 `show({ content })` 로만.
28
42
  */
29
43
  static async alert(message, options) {
30
- await this.show({
44
+ const messageId = nextMessageId();
45
+ await this.present({
31
46
  ...options,
32
- content: asText(message)
33
- });
47
+ content: asText(message, messageId)
48
+ }, (dialog) => describe(dialog, messageId, "alertdialog"));
34
49
  }
35
50
  /**
36
51
  * 확인 다이얼로그를 표시합니다. (확인/취소 버튼)
@@ -38,9 +53,10 @@ var Dialog = class {
38
53
  * @returns 확인이면 true, 취소이면 false
39
54
  */
40
55
  static async confirm(message, options) {
41
- return await this.show({
56
+ const messageId = nextMessageId();
57
+ return await this.present({
42
58
  ...options,
43
- content: asText(message),
59
+ content: asText(message, messageId),
44
60
  actions: [{
45
61
  label: options?.cancelLabel || Locale.getValue("cancel"),
46
62
  value: "cancel",
@@ -50,7 +66,7 @@ var Dialog = class {
50
66
  value: "confirm",
51
67
  color: options?.confirmColor
52
68
  }]
53
- }) === "confirm";
69
+ }, (dialog) => describe(dialog, messageId, "alertdialog")) === "confirm";
54
70
  }
55
71
  /**
56
72
  * 입력 다이얼로그를 표시합니다. (텍스트 입력 + 확인/취소)
@@ -58,11 +74,12 @@ var Dialog = class {
58
74
  */
59
75
  static async prompt(message, options) {
60
76
  let inputValue = options?.defaultValue || "";
61
- return await this.show({
77
+ const messageId = nextMessageId();
78
+ return await this.present({
62
79
  ...options,
63
80
  content: html`
64
81
  <div style="display: flex; flex-direction: column; gap: 12px;">
65
- <div>${message}</div>
82
+ <div id=${messageId}>${message}</div>
66
83
  <u-input
67
84
  type=${options?.type || "text"}
68
85
  placeholder=${options?.placeholder || ""}
@@ -89,13 +106,17 @@ var Dialog = class {
89
106
  label: options?.confirmLabel || Locale.getValue("confirm"),
90
107
  value: "confirm"
91
108
  }]
92
- }) === "confirm" ? inputValue : null;
109
+ }, (dialog) => describe(dialog, messageId, "dialog")) === "confirm" ? inputValue : null;
93
110
  }
94
111
  /**
95
112
  * 커스텀 다이얼로그를 표시합니다.
96
113
  * @returns 클릭된 액션의 value 또는 닫힌 경우 null
97
114
  */
98
- static async show(options) {
115
+ static show(options) {
116
+ return this.present(options);
117
+ }
118
+ /** `show` 의 본체 — `decorate` 는 `alert`·`confirm`·`prompt` 가 렌더 뒤 접근성 이름·설명을 잇는 자리다. */
119
+ static async present(options, decorate) {
99
120
  let closeValue = null;
100
121
  const dialog = this.createDialog(options);
101
122
  const content = typeof options.content === "string" ? unsafeHTML(options.content) : options.content;
@@ -119,6 +140,7 @@ var Dialog = class {
119
140
  ` : nothing}
120
141
  </div>
121
142
  `, dialog);
143
+ decorate?.(dialog);
122
144
  (options.target || document.body).appendChild(dialog);
123
145
  const closed = new Promise((resolve) => {
124
146
  dialog.addEventListener("hide", (e) => {
@@ -152,6 +174,7 @@ var Dialog = class {
152
174
  dialog.closeOn = closeOn;
153
175
  if (options?.title) {
154
176
  const header = document.createElement("span");
177
+ header.id = `u-dialog-title-${++messageSeq}`;
155
178
  header.slot = "header";
156
179
  header.textContent = options.title;
157
180
  dialog.prepend(header);
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.3.1",
4
+ "version": "2.4.0",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -44,6 +44,13 @@ u-dialog { height: 400px; } /* the panel then caps at 360px */
44
44
  ⚠ That lever only shrinks: a height on the host lowers the panel's maximum, it does not reserve a
45
45
  panel of that size. A short dialog stays short.
46
46
 
47
+ ## Accessibility
48
+
49
+ The host is exposed as a **`dialog`**, with `aria-modal` when `mode="modal"`. Its name is whatever sits in the
50
+ `header` slot, and follows that content as it changes. Without a header, name it with `aria-label` (or
51
+ `aria-labelledby`) on the host — attributes on the host override the defaults, including `role="alertdialog"` for a
52
+ message that needs a response.
53
+
47
54
  ## Slots
48
55
 
49
56
  | Name | Description |
@@ -20,6 +20,11 @@ Side panel that slides in from any screen edge. Extends `UOverlayElement` (focus
20
20
 
21
21
  ---
22
22
 
23
+ ## Accessibility
24
+
25
+ Same as `u-dialog`: exposed as a **`dialog`** (`aria-modal` when modal), named by the `header` slot, or by
26
+ `aria-label`/`aria-labelledby` on the host.
27
+
23
28
  ## Slots
24
29
 
25
30
  | Name | Description |
@@ -35,7 +35,7 @@ No drag-and-drop in this version — it is a minimal wrapper (trigger + status +
35
35
 
36
36
  | Property | Type | Default | Reflect | Description |
37
37
  |----------|------|---------|---------|-------------|
38
- | `value` | `File[] \| null` | `null` | — | Selected files (always an array, even for single-file selection) |
38
+ | `value` | `File[] \| null` | `null` | — | Selected files (always an array, even for single-file selection). Setting it to `null` (or `[]`) clears the native input as `reset()` does, so the same file can be picked again |
39
39
  | `accept` | `string` | — | — | Passed through to the native `accept` attribute |
40
40
  | `multiple` | `boolean` | `false` | ✓ | Allow selecting more than one file |
41
41
  | `disabled` | `boolean` | `false` | ✓ | Disable the control |
@@ -132,6 +132,7 @@ Call `preventDefault()` on the `keydown` to cancel it. Do not also submit on Ent
132
132
  |----------|-------------|
133
133
  | `--u-input-display` | Host `display` (default `inline-block`); set `block` to fill a form or grid cell |
134
134
  | `--u-input-width` | Host `width` (default `auto`); set `100%` where `block` alone does not stretch, such as in a flex container |
135
+ | `--input-min-text` | Minimum width of the text area (default `4ch`). The stepper, clear and password-toggle icons never squeeze the text below it — a field given less width overflows its host visibly instead of drawing an input you cannot see into |
135
136
  | `--input-popover-width` | Combobox popover width (fixed to anchor width by default) |
136
137
  | `--input-popover-min-height` | Combobox popover min-height |
137
138
  | `--input-popover-max-height` | Combobox popover max-height |
@@ -21,6 +21,11 @@ Toggle switch (on/off). Supports custom track and thumb content via slots. Form-
21
21
 
22
22
  ---
23
23
 
24
+ ## Accessibility
25
+
26
+ Exposed as a **`switch`** (on/off), not a checkbox — screen readers announce "on"/"off", and role-based queries use
27
+ `getByRole('switch', { name })`. Use `u-checkbox` for a choice that is applied later (on save).
28
+
24
29
  ## Slots
25
30
 
26
31
  | Name | Description |
@@ -50,6 +50,12 @@ confirmation cannot inject markup. For formatting pass a Lit `TemplateResult`
50
50
  (`Dialog.confirm(html\`Delete <strong>${name}</strong>?\`)` — interpolated values stay text). Only
51
51
  `Dialog.show({ content })` takes an HTML string, and says so.
52
52
 
53
+ ## Accessibility
54
+
55
+ `alert` and `confirm` open as an **`alertdialog`** (a message that needs a response — the role a native `confirm()`
56
+ has); `prompt` and `show` open as a **`dialog`**. All are modal unless `modal: false`. With a `title`, the title is the
57
+ dialog's name and the message its description; without one, the message is the name — a dialog is never unnamed.
58
+
53
59
  ## Types
54
60
 
55
61
  ```ts