tyrell-components 1.0.0-rc.21 → 1.0.0-rc.22

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.
@@ -76,7 +76,7 @@ Below 640px fields drop `lg` to 36 and `xl` to 40 (below 480px `xl` to 36). Butt
76
76
  - Options are `ty-option` (not `<option>` or `ty-tag`). The selection is the select's `value`; `<ty-option selected>` selects nothing, so server-rendered HTML carries `value="…"`.
77
77
  - **Up to 7 options: give it a trigger** (`slot="trigger"`). The search row only appears above 7 options, so a short list doesn't need a form field. In toolbars and filter bars, `compact` is the plain alternative.
78
78
  - More options, or typed search: the default field. `external-search` for remote lists, `allow-create` for a tags input.
79
- - A slotted trigger keeps the value, form submit, ARIA, keyboard and the error line. The select takes the click and the keys, so don't add `clickable` to a trigger tag. You render the trigger: show the current value in it and update it on `change`. No × button; call `clear()`.
79
+ - A slotted trigger keeps the value, form submit, ARIA, keyboard and the error line. A trigger that takes focus (`ty-button`, `clickable` tag) is the tab stop; else the select is. You render the trigger: show the current value in it and update it on `change`. No × button; call `clear()`.
80
80
  - The list is at least 320px wide, or as wide as the trigger; `--ty-select-popup-width` sets it.
81
81
  - **Status picker:** the trigger is a `ty-tag` in the current option's flavor, with a chevron.
82
82
 
@@ -430,6 +430,8 @@ THE select control. Single select by default with a form-field look matching `ty
430
430
 
431
431
  On Send, the browser's message for a native `<select>` appears under the field and the trigger takes focus. A user change that leaves it empty shows the message at once; setting the value in code does not.
432
432
 
433
+ **Focus with a custom trigger:** one tab stop. A trigger that can take focus (a `ty-button`, a link, a `clickable` `ty-tag`) is it. The element that actually takes focus (inside `ty-button`, its `<button>`) gets `aria-haspopup="listbox"`, a live `aria-expanded`, `role="button"` if it has no role, and, with `label`, the name "Label: what the trigger shows" (an `aria-label` you set wins); one that can't (a plain `ty-tag`, a `<span>`) leaves the tab stop to the select, which draws the focus ring around it. Enter, Space and ↓ open the list either way; Escape returns focus to the trigger.
434
+
433
435
  **Error line under a custom trigger:** compact and `slot="trigger"` selects show the error line under the trigger. It wraps at a readable width (about 20em), can extend past a narrow trigger, and doesn't widen the host; under a slotted trigger it starts at the trigger's left edge. A slotted trigger keeps its own look (no danger border) and gets `aria-invalid="true"` plus `aria-description` holding the message, both removed when the error clears. Focus from validation lands on the slotted trigger; when the trigger can't take focus (a `<span>`), on the select's own field.
434
436
 
435
437
  **Custom colors:** uses the shared `--ty-input-*` variable family — override per select with `--ty-input-bg`, `--ty-input-border`, `--ty-input-border-focus`, `--ty-input-shadow-focus`, etc. See [CSS_GUIDE.md → Per-Component Color Overrides](./CSS_GUIDE.md#per-component-color-overrides).
@@ -12,8 +12,8 @@ For shadow-cljs, CSS, and icon basics, see [CLOJURESCRIPT_GUIDE.md](CLOJURESCRIP
12
12
 
13
13
  ```clojure
14
14
  {:deps {lilactown/helix {:mvn/version "0.2.0"}
15
- dev.gersak/tyrell {:mvn/version "1.0.0-RC20"}
16
- dev.gersak/tyrell-icons-lucide {:mvn/version "1.0.0-RC20"}}} ; tyrell.lucide
15
+ dev.gersak/tyrell {:mvn/version "1.0.0-rc.21"}
16
+ dev.gersak/tyrell-icons-lucide {:mvn/version "1.0.0-rc.21"}}} ; tyrell.lucide
17
17
  ```
18
18
 
19
19
  `tyrell.react` is part of `dev.gersak/tyrell`; install React + the wrapper package via npm:
@@ -10,8 +10,8 @@ This guide focuses on what's specific to Reagent + Tyrell. For shadow-cljs, CSS,
10
10
 
11
11
  ```clojure
12
12
  {:deps {reagent/reagent {:mvn/version "1.2.0"}
13
- dev.gersak/tyrell {:mvn/version "1.0.0-RC20"}
14
- dev.gersak/tyrell-icons-lucide {:mvn/version "1.0.0-RC20"}}} ; tyrell.lucide
13
+ dev.gersak/tyrell {:mvn/version "1.0.0-rc.21"}
14
+ dev.gersak/tyrell-icons-lucide {:mvn/version "1.0.0-rc.21"}}} ; tyrell.lucide
15
15
  ```
16
16
 
17
17
  `tyrell.react` ships inside `dev.gersak/tyrell` and re-exports the npm wrappers. The npm package isn't auto-pulled — install it explicitly:
@@ -30,8 +30,8 @@ For offline dev, fetch the files once and serve them from your `public/`:
30
30
 
31
31
  ```bash
32
32
  # Pin a version
33
- curl -o public/css/tyrell.css https://cdn.jsdelivr.net/npm/tyrell-components@1.0.0-RC20/css/tyrell.css
34
- curl -o public/css/tyrell-theme.css https://cdn.jsdelivr.net/npm/tyrell-components@1.0.0-RC20/css/tyrell-theme.css
33
+ curl -o public/css/tyrell.css https://cdn.jsdelivr.net/npm/tyrell-components@1.0.0-rc.21/css/tyrell.css
34
+ curl -o public/css/tyrell-theme.css https://cdn.jsdelivr.net/npm/tyrell-components@1.0.0-rc.21/css/tyrell-theme.css
35
35
 
36
36
  # Or copy from the version shadow-cljs already installed (after first build)
37
37
  cp node_modules/tyrell-components/css/tyrell.css public/css/tyrell.css
@@ -11,8 +11,8 @@ This guide covers what's specific to UIx + Tyrell. For framework-agnostic CLJS s
11
11
  ```clojure
12
12
  {:deps {com.pitch/uix.core {:mvn/version "1.4.4"}
13
13
  com.pitch/uix.dom {:mvn/version "1.4.4"}
14
- dev.gersak/tyrell {:mvn/version "1.0.0-RC20"}
15
- dev.gersak/tyrell-icons-lucide {:mvn/version "1.0.0-RC20"}}} ; tyrell.lucide
14
+ dev.gersak/tyrell {:mvn/version "1.0.0-rc.21"}
15
+ dev.gersak/tyrell-icons-lucide {:mvn/version "1.0.0-rc.21"}}} ; tyrell.lucide
16
16
  ```
17
17
 
18
18
  `tyrell.react` is part of `dev.gersak/tyrell`, but the npm wrapper package isn't auto-pulled. Install it explicitly the same way you install React itself:
@@ -171,6 +171,7 @@ export declare class TySelect extends TyComponent<SelectState> {
171
171
  private _customFlavorSheet;
172
172
  private _ariaTrigger;
173
173
  private _ariaObserver;
174
+ private _triggerTextObserver;
174
175
  constructor();
175
176
  /** TyComponent renders right after this on the first connect. */
176
177
  protected onConnect(): void;
@@ -340,6 +341,17 @@ export declare class TySelect extends TyComponent<SelectState> {
340
341
  * :host()); render() puts it back if a morph strips it.
341
342
  */
342
343
  private syncTriggerSlot;
344
+ private slottedTrigger;
345
+ private triggerTakesFocus;
346
+ /** The element a slotted trigger takes focus on, which is where its ARIA must go; null if it can't. */
347
+ private triggerAriaTarget;
348
+ /**
349
+ * Name the control after the select's label and what the trigger shows:
350
+ * "Sort: Newest". An aria-label the author put there wins. A trigger that
351
+ * can't take focus leaves the stub as the control: without a label it is
352
+ * named after the trigger's text.
353
+ */
354
+ private syncTriggerName;
343
355
  /**
344
356
  * Build the shadow DOM once. Mobile (touch, narrow) gets a full-screen
345
357
  * dialog with a selected strip; desktop an anchored dropdown. The mode is
@@ -13,6 +13,12 @@ import { REQUIRED_ICON_SVG } from "../utils/icons.js";
13
13
  import { nativeMessage } from "../utils/validity.js";
14
14
  let selectCount = 0;
15
15
  const SEARCH_AUTO_THRESHOLD = 7;
16
+ const TABBABLE = 'button:not([disabled]), a[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
17
+ function triggerFocusTarget(trigger) {
18
+ if (trigger.matches(TABBABLE))
19
+ return trigger;
20
+ return (trigger.shadowRoot?.querySelector(TABBABLE) ?? trigger.querySelector(TABBABLE));
21
+ }
16
22
  const CHEVRON_DOWN_SVG = `<svg viewBox="0 0 20 20" fill="currentColor">
17
23
  <path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd" />
18
24
  </svg>`;
@@ -64,6 +70,7 @@ this._childObserver = null;
64
70
  this._customFlavorSheet = null;
65
71
  this._ariaTrigger = null;
66
72
  this._ariaObserver = null;
73
+ this._triggerTextObserver = null;
67
74
  const shadow = this.shadowRoot;
68
75
  ensureStyles(shadow, { css: selectBaseStyles, id: "ty-select-base" });
69
76
  ensureStyles(shadow, { css: selectStyles, id: "ty-select" });
@@ -156,11 +163,12 @@ return formData;
156
163
  focus(options) {
157
164
  if (this.disabled)
158
165
  return;
159
- const trigger = this.querySelector(':scope > [slot="trigger"]');
160
- if (trigger) {
161
- trigger.focus(options);
162
- const active = trigger.getRootNode().activeElement;
163
- if (active && trigger.contains(active))
166
+ const trigger = this.slottedTrigger();
167
+ const target = trigger && triggerFocusTarget(trigger);
168
+ if (target) {
169
+ target.focus(options);
170
+ const root = target.getRootNode();
171
+ if (root.activeElement === target)
164
172
  return;
165
173
  }
166
174
  const stub = this.shadowRoot?.querySelector(".select-stub");
@@ -356,6 +364,7 @@ this._scrollLockId = null;
356
364
  }
357
365
  setExpanded(expanded) {
358
366
  this.shadowRoot.querySelector(".select-stub")?.setAttribute("aria-expanded", String(expanded));
367
+ this.triggerAriaTarget()?.setAttribute("aria-expanded", String(expanded));
359
368
  }
360
369
  openDropdown() {
361
370
  const shadow = this.shadowRoot;
@@ -789,16 +798,17 @@ const stub = shadow.querySelector(".select-stub");
789
798
  stub.classList.toggle("disabled", disabled);
790
799
  stub.classList.toggle("compact", this.compact);
791
800
  stub.classList.toggle("error", !!error);
792
- stub.tabIndex = disabled ? -1 : 0;
801
+ stub.tabIndex = disabled || this.triggerTakesFocus() ? -1 : 0;
793
802
  stub.toggleAttribute("disabled", disabled);
794
803
  if (disabled)
795
804
  stub.setAttribute("aria-disabled", "true");
796
805
  else
797
806
  stub.removeAttribute("aria-disabled");
798
- if (labelText)
807
+ if (labelText && !this.triggerTakesFocus())
799
808
  stub.setAttribute("aria-labelledby", labelId);
800
809
  else
801
810
  stub.removeAttribute("aria-labelledby");
811
+ this.syncTriggerName();
802
812
  if (error) {
803
813
  stub.setAttribute("aria-invalid", "true");
804
814
  stub.setAttribute("aria-describedby", errorId);
@@ -814,9 +824,7 @@ shadow
814
824
  }
815
825
  syncTriggerAria() {
816
826
  const error = this.error || "";
817
- const trigger = error
818
- ? this.querySelector(':scope > [slot="trigger"]')
819
- : null;
827
+ const trigger = error ? (this.triggerAriaTarget() ?? this.slottedTrigger()) : null;
820
828
  if (this._ariaTrigger && this._ariaTrigger !== trigger) {
821
829
  this._ariaTrigger.removeAttribute("aria-invalid");
822
830
  this._ariaTrigger.removeAttribute("aria-description");
@@ -854,10 +862,79 @@ syncTriggerSlot() {
854
862
  const shadow = this.shadowRoot;
855
863
  const slot = shadow.querySelector('slot[name="trigger"]');
856
864
  const hasTrigger = slot.assignedElements().length > 0;
857
- shadow.querySelector(".select-stub").classList.toggle("custom-trigger", hasTrigger);
865
+ const stub = shadow.querySelector(".select-stub");
866
+ stub.classList.toggle("custom-trigger", hasTrigger);
858
867
  if (this.hasAttribute("has-trigger") !== hasTrigger) {
859
868
  this.toggleAttribute("has-trigger", hasTrigger);
860
869
  }
870
+ const trigger = this.slottedTrigger();
871
+ const target = this.triggerAriaTarget();
872
+ stub.tabIndex = this.disabled || target ? -1 : 0;
873
+ if (target) {
874
+ target.setAttribute("aria-haspopup", "listbox");
875
+ target.setAttribute("aria-expanded", String(this._state.open));
876
+ if (!target.matches("button, a[href], input, select, textarea") && !target.hasAttribute("role")) {
877
+ target.setAttribute("role", "button");
878
+ }
879
+ stub.setAttribute("role", "none");
880
+ for (const a of ["aria-haspopup", "aria-expanded", "aria-controls", "aria-labelledby"])
881
+ stub.removeAttribute(a);
882
+ }
883
+ else if (stub.getAttribute("role") !== "combobox") {
884
+ stub.setAttribute("role", "combobox");
885
+ stub.setAttribute("aria-haspopup", "listbox");
886
+ stub.setAttribute("aria-expanded", String(this._state.open));
887
+ stub.setAttribute("aria-controls", `select-listbox-${this._uid}`);
888
+ }
889
+ this._triggerTextObserver?.disconnect();
890
+ if (trigger) {
891
+ this._triggerTextObserver ?? (this._triggerTextObserver = new MutationObserver(() => this.syncTriggerName()));
892
+ this._triggerTextObserver.observe(trigger, { childList: true, characterData: true, subtree: true });
893
+ }
894
+ this.syncTriggerName();
895
+ if (trigger && trigger.localName.includes("-") && !customElements.get(trigger.localName)) {
896
+ customElements.whenDefined(trigger.localName).then(() => requestAnimationFrame(() => this.syncTriggerSlot()));
897
+ }
898
+ }
899
+ slottedTrigger() {
900
+ return this.querySelector(':scope > [slot="trigger"]');
901
+ }
902
+ triggerTakesFocus() {
903
+ return !!this.triggerAriaTarget();
904
+ }
905
+ triggerAriaTarget() {
906
+ const trigger = this.slottedTrigger();
907
+ return trigger ? triggerFocusTarget(trigger) : null;
908
+ }
909
+ syncTriggerName() {
910
+ const trigger = this.slottedTrigger();
911
+ const stub = this.shadowRoot?.querySelector(".select-stub");
912
+ if (!stub)
913
+ return;
914
+ const text = (trigger?.textContent || "").replace(/\s+/g, " ").trim();
915
+ const label = this.label ? String(this.label) : "";
916
+ const target = this.triggerAriaTarget();
917
+ if (!target) {
918
+ if (trigger && !label && text)
919
+ stub.setAttribute("aria-label", text);
920
+ else
921
+ stub.removeAttribute("aria-label");
922
+ return;
923
+ }
924
+ stub.removeAttribute("aria-label");
925
+ const owned = target.hasAttribute("data-ty-select-name");
926
+ if (target.hasAttribute("aria-label") && !owned)
927
+ return;
928
+ if (label) {
929
+ const name = text ? `${label}: ${text}` : label;
930
+ if (target.getAttribute("aria-label") !== name)
931
+ target.setAttribute("aria-label", name);
932
+ target.setAttribute("data-ty-select-name", "");
933
+ }
934
+ else if (owned) {
935
+ target.removeAttribute("aria-label");
936
+ target.removeAttribute("data-ty-select-name");
937
+ }
861
938
  }
862
939
  build() {
863
940
  const shadow = this.shadowRoot;
@@ -239,6 +239,11 @@ background: transparent;
239
239
  border-color: transparent;
240
240
  box-shadow: none;
241
241
  }
242
+ .select-stub.custom-trigger:focus-visible {
243
+ outline: 2px solid var(--select-accent-bold, var(--ty-input-border-focus, var(--ty-color-primary, currentColor)));
244
+ outline-offset: 2px;
245
+ border-radius: var(--ty-radius-md);
246
+ }
242
247
  .error-message {
243
248
  font-size: var(--ty-font-xs);
244
249
  line-height: var(--ty-leading-xs);
package/lib/version.d.ts CHANGED
@@ -4,4 +4,4 @@
4
4
  * This is automatically synced with package.json during build.
5
5
  * Use `npm version` to bump versions.
6
6
  */
7
- export declare const VERSION = "1.0.0-rc.21";
7
+ export declare const VERSION = "1.0.0-rc.22";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '1.0.0-rc.21';
1
+ export const VERSION = '1.0.0-rc.22';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tyrell-components",
3
- "version": "1.0.0-rc.21",
3
+ "version": "1.0.0-rc.22",
4
4
  "description": "Tyrell Components - Framework-agnostic web components with semantic design system",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -11,6 +11,9 @@
11
11
  "main": "./lib/index.js",
12
12
  "module": "./lib/index.js",
13
13
  "types": "./lib/index.d.ts",
14
+ "bin": {
15
+ "tyrell-components": "bin/tyrell.mjs"
16
+ },
14
17
  "exports": {
15
18
  ".": {
16
19
  "types": "./lib/index.d.ts",
@@ -143,7 +146,8 @@
143
146
  "LICENSE",
144
147
  "AGENTS.md",
145
148
  "guides/**/*",
146
- "CHANGELOG.md"
149
+ "CHANGELOG.md",
150
+ "bin/**/*"
147
151
  ],
148
152
  "keywords": [
149
153
  "web-components",