@astryxdesign/core 0.7.2-canary.e2909cf → 0.7.2-canary.fbc03f7
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/Breadcrumbs/BreadcrumbItem.d.ts.map +1 -1
- package/dist/Breadcrumbs/BreadcrumbItem.js +5 -2
- package/dist/ContextMenu/ContextMenu.d.ts.map +1 -1
- package/dist/ContextMenu/ContextMenu.js +5 -2
- package/dist/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenu.js +46 -3
- package/dist/DropdownMenu/DropdownMenuContext.d.ts +17 -0
- package/dist/DropdownMenu/DropdownMenuContext.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuContext.js +21 -0
- package/dist/DropdownMenu/DropdownMenuSubMenu.d.ts.map +1 -1
- package/dist/DropdownMenu/DropdownMenuSubMenu.js +15 -4
- package/dist/Field/Field.d.ts +1 -1
- package/dist/Field/Field.d.ts.map +1 -1
- package/dist/Field/Field.js +8 -4
- package/dist/Grid/GridSpan.d.ts.map +1 -1
- package/dist/Grid/GridSpan.js +1 -0
- package/dist/MetadataList/MetadataList.d.ts.map +1 -1
- package/dist/MetadataList/MetadataList.js +5 -1
- package/dist/MetadataList/MetadataListContext.d.ts +1 -1
- package/dist/MetadataList/MetadataListContext.d.ts.map +1 -1
- package/dist/RadioList/RadioList.d.ts +1 -1
- package/dist/RadioList/RadioList.d.ts.map +1 -1
- package/dist/RadioList/RadioList.js +6 -2
- package/dist/ToggleButton/ToggleButton.d.ts +3 -2
- package/dist/ToggleButton/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButton/ToggleButton.js +12 -1
- package/dist/astryx.css +1 -0
- package/dist/hooks/useMenuHover.d.ts.map +1 -1
- package/dist/hooks/useMenuHover.js +18 -13
- package/package.json +3 -3
- package/src/Avatar/Avatar.doc.mjs +5 -3
- package/src/AvatarGroup/AvatarGroup.doc.mjs +3 -2
- package/src/Breadcrumbs/BreadcrumbItem.tsx +4 -1
- package/src/Chat/__tests__/ChatMessageMetadata.a11y.chromium.spec.ts +3 -1
- package/src/ContextMenu/ContextMenu.tsx +4 -1
- package/src/DropdownMenu/DropdownMenu.tsx +45 -2
- package/src/DropdownMenu/DropdownMenuContext.tsx +24 -0
- package/src/DropdownMenu/DropdownMenuSubMenu.test.tsx +185 -0
- package/src/DropdownMenu/DropdownMenuSubMenu.tsx +17 -3
- package/src/Field/Field.doc.mjs +14 -8
- package/src/Field/Field.spec.md +217 -0
- package/src/Field/Field.test.tsx +60 -2
- package/src/Field/Field.tsx +17 -8
- package/src/Grid/GridSpan.tsx +3 -0
- package/src/MetadataList/MetadataList.doc.mjs +2 -2
- package/src/MetadataList/MetadataList.test.tsx +38 -0
- package/src/MetadataList/MetadataList.tsx +8 -1
- package/src/MetadataList/MetadataListContext.tsx +1 -1
- package/src/RadioList/RadioList.fr10.test.tsx +45 -2
- package/src/RadioList/RadioList.tsx +4 -1
- package/src/Slider/Slider.spec.md +39 -18
- package/src/TimeInput/TimeInput.fr10.test.tsx +15 -0
- package/src/ToggleButton/ToggleButton.test.tsx +95 -0
- package/src/ToggleButton/ToggleButton.tsx +12 -1
- package/src/docPropLiterals.test.ts +36 -10
- package/src/hooks/useMenuHover.ts +18 -13
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
---
|
|
2
|
+
schema_version: 3
|
|
3
|
+
template_version: 7
|
|
4
|
+
kind: component
|
|
5
|
+
id: component:Field
|
|
6
|
+
authority: draft
|
|
7
|
+
archive_reason: null
|
|
8
|
+
superseded_by: null
|
|
9
|
+
approved_by: null
|
|
10
|
+
approved_at: null
|
|
11
|
+
owners: [cixzhang]
|
|
12
|
+
review_triggers: [public-api, behavior, layout, theming, accessibility]
|
|
13
|
+
verified_by:
|
|
14
|
+
[
|
|
15
|
+
packages/core/src/Field/Field.test.tsx,
|
|
16
|
+
packages/core/src/theme/themingTargets.test.ts,
|
|
17
|
+
packages/core/src/docPropLiterals.test.ts,
|
|
18
|
+
packages/core/src/docPropReferences.test.ts,
|
|
19
|
+
]
|
|
20
|
+
modules: []
|
|
21
|
+
families: [family:input-fields]
|
|
22
|
+
design_specs:
|
|
23
|
+
[design:spatial-hierarchy, design:typography-hierarchy, design:system-states]
|
|
24
|
+
architecture:
|
|
25
|
+
[
|
|
26
|
+
architecture:public-component-api,
|
|
27
|
+
architecture:component-theming-surface,
|
|
28
|
+
architecture:component-test-sufficiency,
|
|
29
|
+
]
|
|
30
|
+
contributing: []
|
|
31
|
+
system_specs:
|
|
32
|
+
[spec:AST-027/FR1, spec:AST-027/FR2, spec:AST-027/FR3, spec:AST-027/FR11]
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
# Field component contract
|
|
36
|
+
|
|
37
|
+
## Contract at a glance
|
|
38
|
+
|
|
39
|
+
| Area | Contract |
|
|
40
|
+
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
41
|
+
| Public contract | `Field` wraps one caller-owned control with a label, optional description and status, optionality indicators, an explicit width, and root `BaseProps`; it also consumes FormLayout's horizontal-label mode. |
|
|
42
|
+
| Behavior | Single controls use a native label association; groups use a labelled span. Status messages receive stable IDs and use persistent live regions. Horizontal-label mode exposes one protected `data-layout` theme axis. |
|
|
43
|
+
| End-user impact | People can identify a custom control, hear its description and changing status, and keep label/control/status relationships together across ordinary and horizontal form layouts. |
|
|
44
|
+
| Builder impact | Builders provide the control and its ID, wire descriptions/status IDs to that control, choose group semantics when needed, and use a status placement that is safe for the wrapped surface. |
|
|
45
|
+
| Compatibility/readiness | This draft records released behavior. It adds no API or policy. The released default `statusVariant="attached"` for arbitrary children conflicts with the capability boundary in `family:input-fields/FR8` and remains open. |
|
|
46
|
+
| Review checks | Reject a lost label/group association, dropped root props, caller replacement of `data-layout`, duplicate/missing status announcement, escaped local z-index, undocumented public literals, or a claim that all custom controls safely support attached status. |
|
|
47
|
+
| Governing rules | Established public `Field` interface; `family:input-fields` shared ownership and FR8; `architecture:public-component-api/INV5–INV8`; `spec:AST-027/FR1–FR3`; HTML label and ARIA naming/description semantics. |
|
|
48
|
+
|
|
49
|
+
This table is a review projection; the body below is authoritative.
|
|
50
|
+
|
|
51
|
+
## Intent
|
|
52
|
+
|
|
53
|
+
`Field` supplies shared label, description, status, width, and layout chrome for a native, custom, or third-party control that does not already own an Astryx field shell. The caller continues to own the control's value, interaction model, and control-specific accessibility semantics.
|
|
54
|
+
|
|
55
|
+
## Compatibility and migration
|
|
56
|
+
|
|
57
|
+
- Released default preserved: yes; `statusVariant` still defaults to `attached` in the current implementation.
|
|
58
|
+
- Compatibility class: observational only; this draft changes no public prop, default, or behavior.
|
|
59
|
+
- Controlled/uncontrolled behavior: caller-owned and unchanged.
|
|
60
|
+
- Migration decision: none; resolving OQ1 requires a separate compatibility decision.
|
|
61
|
+
|
|
62
|
+
## Ownership boundary
|
|
63
|
+
|
|
64
|
+
**Owns**
|
|
65
|
+
|
|
66
|
+
- The root field box, explicit width, local stacking boundary, and composition order.
|
|
67
|
+
- Label and description placement around the caller-owned control.
|
|
68
|
+
- Single-control versus grouped-label semantics.
|
|
69
|
+
- Status-message placement and persistent live-region announcement.
|
|
70
|
+
- The FormLayout horizontal-label projection.
|
|
71
|
+
|
|
72
|
+
**Does not own / non-goals**
|
|
73
|
+
|
|
74
|
+
- The wrapped control's value, focus model, keyboard behavior, disabled behavior, or event semantics — owned by the caller or wrapped component.
|
|
75
|
+
- Applying `aria-describedby` to the wrapped control — the caller supplies the control and wires the generated or explicit IDs.
|
|
76
|
+
- The visual and semantic contract of `FieldLabel`, `FieldStatus`, `Tooltip`, or caller-owned children — owned by those components.
|
|
77
|
+
- Input-family member APIs and control-box part props — owned by `family:input-fields` and each member.
|
|
78
|
+
|
|
79
|
+
## Public concepts
|
|
80
|
+
|
|
81
|
+
| Concept | Closed values or states | Meaning | Availability by variant/orientation/state | Default | Owner | Stability | Invalid-value behavior |
|
|
82
|
+
| ---------------------- | ------------------------------------------------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- | ------------------------------ | --------------------- | ------------------------- | ------------------------------------- |
|
|
83
|
+
| label mode | single control; group | Chooses a native `<label htmlFor>` or a `<span>` named through `aria-labelledby`. | All layouts. | single control | `component:Field` | released | Type-constrained |
|
|
84
|
+
| label visibility | visible; visually hidden | Hides label and description visually while preserving them for assistive technology. | All layouts. | visible | `component:Field` | released | Type-constrained |
|
|
85
|
+
| optionality marker | none; optional; required | Shows the localized exception to FormLayout's optionality default. | Label presentation. | none | `component:Field` | released | Both set warns; optional wins visibly |
|
|
86
|
+
| status placement | `attached`; `detached`; `tooltip` | Places a status box behind the control, below it, or leaves visible tooltip affordance to input. | Message required for a rendered box; tooltip still announces messages. | `attached` (see OQ1) | `family:input-fields` | released; conformance gap | Type-constrained |
|
|
87
|
+
| width | absent; number; CSS size string | Sizes the complete ordinary field box. | Ordinary box layout; horizontal-label mode uses `display: contents`. | containing layout | `component:Field` | released | Type-constrained |
|
|
88
|
+
| field layout | ordinary box; `horizontal-labels` from FormLayout | Stacks content or projects label and input group into the parent grid. | Resolved from `FormLayoutContext`. | ordinary box | `component:Field` | released | Context-constrained |
|
|
89
|
+
| description/status IDs | explicit; generated from `inputID`; absent | Names stable description and message elements for caller-owned `aria-describedby` wiring. | Generated only when the corresponding text is present. | generated when text is present | `component:Field` | released | Empty text omits output |
|
|
90
|
+
|
|
91
|
+
## Behavioral and layout contract
|
|
92
|
+
|
|
93
|
+
Draft requirements identify their basis so observed code is not mistaken for an intentional decision.
|
|
94
|
+
|
|
95
|
+
| ID | Candidate invariant | Basis | Draft review state |
|
|
96
|
+
| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- | ----------------------------------- |
|
|
97
|
+
| FR1 | A single-control label renders as `<label htmlFor={inputID}>`; a group label renders as a non-label element with `labelID` for caller-owned `aria-labelledby`. | Established public interface; HTML and ARIA semantics | settled observation |
|
|
98
|
+
| FR2 | Visually hidden labels and descriptions remain in the DOM and out of layout flow. | Established public interface and accessibility behavior | settled observation |
|
|
99
|
+
| FR3 | Description and status IDs use explicit values when supplied and otherwise resolve to `${inputID}-desc` and `${inputID}-status` only when text exists. | Established public interface | settled observation |
|
|
100
|
+
| FR4 | Error status messages announce assertively and warning/success messages politely through persistent live regions; tooltip placement renders no `FieldStatus` box but preserves the announcement. | Existing tests; family ownership | settled observation |
|
|
101
|
+
| FR5 | Ordinary layout orders label, control, then optional status. Horizontal-label mode places the label wrapper before one description/control/status group and reflects `data-layout="horizontal-labels"`; caller props cannot replace that owned theme marker. | Established layout interface; `architecture:public-component-api/INV5` | settled observation |
|
|
102
|
+
| FR6 | `width` applies to the ordinary root field box; it does not style the caller-owned control and has no box to target in horizontal-label mode. | Established public interface; `family:input-fields` shared owner | settled observation |
|
|
103
|
+
| FR7 | Root ref, data/ARIA/DOM inputs, events, `xstyle`, class name, and inline style reach or compose on the root without replacing component-owned semantics. | `architecture:public-component-api/INV5–INV8` | settled observation |
|
|
104
|
+
| FR8 | The Field root isolates every local attached-status paint relationship without assigning the root a page-level z-index. | `spec:AST-027/FR1–FR3`, `FR11` | settled observation |
|
|
105
|
+
| FR9 | Attached status is safe only for an opaque, bordered, fixed-height control with reliable size reflection; custom, tall, wrapped, translucent, or non-bordered controls use detached or component-owned placement. | `family:input-fields/FR8`; current default mismatch | human decision for released default |
|
|
106
|
+
|
|
107
|
+
### Allowed variation
|
|
108
|
+
|
|
109
|
+
- **AV1 — Caller-owned control.** Any control markup may occupy the slot; Field does not inspect, clone, or change it.
|
|
110
|
+
- **AV2 — Form arrangement.** FormLayout may choose ordinary or horizontal-label arrangement without changing label, description, status, or announcement ownership.
|
|
111
|
+
- **AV3 — Status surface.** Eligible controls may use attached placement; other controls use detached or a member-owned tooltip presentation.
|
|
112
|
+
|
|
113
|
+
### Representative states
|
|
114
|
+
|
|
115
|
+
| State | Required invariant | Allowed variation |
|
|
116
|
+
| ----------------- | ------------------------------------------------------------------------------ | ---------------------------------------------------------- |
|
|
117
|
+
| label only | One associated label precedes the caller-owned control. | Visible or visually hidden. |
|
|
118
|
+
| description | One description element receives the resolved ID. | Caller may use an explicit ID or the generated value. |
|
|
119
|
+
| group | Group label is not a literal `<label>` and is referenceable by ID. | Caller owns the group role and `aria-labelledby`. |
|
|
120
|
+
| status | Message receives resolved ID and is announced once on its urgency channel. | Attached/detached box or tooltip-owned visible affordance. |
|
|
121
|
+
| horizontal labels | Label and input group participate in the parent grid and retain `data-layout`. | Description/status may be absent. |
|
|
122
|
+
| explicit width | Ordinary root receives the requested size and remains shrinkable. | Number or CSS size string. |
|
|
123
|
+
|
|
124
|
+
### Transformation and precedence order
|
|
125
|
+
|
|
126
|
+
- **ORD1 — Root props.** Caller DOM/data/event props are forwarded first; Field-owned visual-state reflection is applied afterward; StyleX, caller class, and caller inline style compose in the documented order.
|
|
127
|
+
- **ORD2 — IDs.** Explicit description/status ID wins; otherwise text presence derives an ID from `inputID`; absent text produces no ID-bearing element.
|
|
128
|
+
- **ORD3 — Optionality.** FormLayout default optionality suppresses the matching visible marker; if both local booleans are true, Field warns and the optional marker wins visibly.
|
|
129
|
+
|
|
130
|
+
### Performance and resources
|
|
131
|
+
|
|
132
|
+
- **PR1 — No per-field global resource.** Field owns no listener, observer, timer, or external store. Status announcement delegates to the shared persistent live-region runtime.
|
|
133
|
+
|
|
134
|
+
## Accessibility contract
|
|
135
|
+
|
|
136
|
+
- **AR1 — Label association.** Single controls receive a native label association; grouped controls use caller-wired `aria-labelledby` and never a misleading literal `<label>`.
|
|
137
|
+
- **AR2 — Description association.** Description text remains separate from the accessible name and exposes a stable ID for caller-owned `aria-describedby`.
|
|
138
|
+
- **AR3 — Status announcement.** Changing status text is announced through the persistent live region, including tooltip placement where no message box renders.
|
|
139
|
+
- **AR4 — Hidden labels.** Visually hidden label and description text remain available to assistive technology.
|
|
140
|
+
|
|
141
|
+
## Design relationships
|
|
142
|
+
|
|
143
|
+
| Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
|
|
144
|
+
| ----------------------------- | -------------------------------------------------------- | ------------------------------------------------------ | ------------------------- | ------------------ |
|
|
145
|
+
| Label and description | `design:typography-hierarchy/DR4`, `DR6` | prescribed roles; exact tuning remains token-owned | label and supporting text | FR1–FR3 |
|
|
146
|
+
| Label/control/status grouping | `design:spatial-hierarchy` local and group relationships | prescribed relationship; exact gap remains token-owned | one field group | FR5 |
|
|
147
|
+
| Semantic status | `design:system-states/DR2` | delegated to FieldStatus and wrapped input | supporting feedback | FR4, FR9 |
|
|
148
|
+
|
|
149
|
+
### Theming anatomy
|
|
150
|
+
|
|
151
|
+
<!-- anatomy-theming:v1 -->
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"Container": {"target": "field"},
|
|
156
|
+
"Label": {"target": "field-label"},
|
|
157
|
+
"Ordinary description": {
|
|
158
|
+
"none": {
|
|
159
|
+
"reason": "reachability-gap: The ordinary-layout description paints supporting text outside the field-label target and has no current public target of its own."
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"Horizontal-label description": {
|
|
163
|
+
"delegatesTo": {"owner": "component:Text", "target": "text"}
|
|
164
|
+
},
|
|
165
|
+
"Control slot": {
|
|
166
|
+
"none": {
|
|
167
|
+
"reason": "intentional: The wrapped control is caller-owned or another Astryx component and retains its own theming surface."
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
"Status message": {"target": "field-status"},
|
|
171
|
+
"Input status icon": {"target": "input-status-icon"},
|
|
172
|
+
"Input clear button": {"target": "input-clear-button"},
|
|
173
|
+
"Input clear icon": {"target": "input-clear-icon"},
|
|
174
|
+
"Optional/Required indicator": {"inherits": "field-label"},
|
|
175
|
+
"Label tooltip trigger": {
|
|
176
|
+
"delegatesTo": {"owner": "component:Icon", "target": "icon"}
|
|
177
|
+
},
|
|
178
|
+
"Label tooltip surface": {
|
|
179
|
+
"delegatesTo": {"owner": "component:Tooltip", "target": "tooltip"}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The ordinary description remains stable consumer anatomy without a Field-owned target. A visible horizontal-label description delegates to `Text/text`; when `isLabelHidden` is true, the same content delegates to `VisuallyHidden` and exposes no painted target. The label tooltip splits its visible `Icon/icon` trigger from its layer-hosted `Tooltip/tooltip` surface.
|
|
185
|
+
|
|
186
|
+
## Family and system relationships
|
|
187
|
+
|
|
188
|
+
- `family:input-fields` owns shared status-placement capability and identifies Field as the standalone label, description, status-placement, and explicit-width owner.
|
|
189
|
+
- `architecture:public-component-api` owns root prop, style, event, and ref composition.
|
|
190
|
+
- `architecture:component-theming-surface` owns anatomy qualification and target disposition.
|
|
191
|
+
- `architecture:component-test-sufficiency` owns mutation-sensitive evidence and bounded partitions.
|
|
192
|
+
- `spec:AST-027` owns the isolated local paint relationship between the control and attached status.
|
|
193
|
+
|
|
194
|
+
## Verification map
|
|
195
|
+
|
|
196
|
+
| Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
|
|
197
|
+
| ------------------------ | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | --------------------------- |
|
|
198
|
+
| FR1–FR3, AR1–AR2, AR4 | `Field.test.tsx` DOM/accessibility tests | single control, group, visible/hidden label, explicit/generated IDs | A lost association, wrong element, missing hidden text, or wrong ID fails. | `audit:Field/accessibility` |
|
|
199
|
+
| FR4, AR3 | `Field.test.tsx` announcement tests plus exact-head browser accessibility evidence | first mount, update, repeat, error, warning, attached, detached, tooltip | A missing, duplicate, stale, or wrong-urgency announcement fails. | `audit:Field/accessibility` |
|
|
200
|
+
| FR5–FR7, ORD1 | `Field.test.tsx`, BaseProps lint, theming-target tests, and exact-head visual evidence | ordinary/horizontal layout; class/style/xstyle/data/event/ref; description/status | Dropped caller input, replaceable layout marker, wrong order, or lost target fails. | `audit:Field/api` |
|
|
201
|
+
| FR8 | computed-style tests and exact-head browser rendering | attached, detached, tooltip, no status | Removing isolation or ranking the root outside its parent fails. | `audit:Field/code-health` |
|
|
202
|
+
| FR9 | family contract review and component-owned visual evidence | eligible bordered control; custom/tall/non-bordered control | Attached placement on an ineligible surface remains visible as the current conformance gap. | `audit:Field/behavior` |
|
|
203
|
+
| Theming anatomy | knowledge validation and theming-target tests | Field root, label, description, caller control, status, shared input affordances, indicator, tooltip | Missing, duplicate, or wrongly owned dispositions fail. | `audit:Field/theming` |
|
|
204
|
+
| Documentation projection | docs typecheck and prop literal/reference tests | labelIcon; all status placements; anatomy and usage guidance | Docs omit or misstate a public type/literal/owner and validation fails or review rejects it. | `audit:Field/docs` |
|
|
205
|
+
| RTL applicability | exact-head RTL audit and verified-N/A registry | all checked-in Field stories and source | A directional glyph, physical inline placement, order, scroll/drag, overlay, or directional keyboard behavior makes N/A stale. | `audit:Field/i18n-rtl` |
|
|
206
|
+
|
|
207
|
+
## Decision log
|
|
208
|
+
|
|
209
|
+
No component-local decision is asserted. This draft records released behavior and leaves the current family-owned status-placement conflict in OQ1.
|
|
210
|
+
|
|
211
|
+
## Open questions
|
|
212
|
+
|
|
213
|
+
- **OQ1 — How should Field migrate the released `attached` default so arbitrary custom controls cannot receive a placement that `family:input-fields/FR8` says they may not safely support?** (`human-api`)
|
|
214
|
+
|
|
215
|
+
## Content boundary
|
|
216
|
+
|
|
217
|
+
This draft records verified shipped behavior and the current family-owned conformance gap. It does not approve a new default, migration, theme target, or compatibility promise, and it does not duplicate audit scores or run evidence.
|
package/src/Field/Field.test.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @file Field.test.tsx
|
|
5
|
-
* @input Uses
|
|
5
|
+
* @input Uses Vitest, Testing Library, StyleX, Field, FormLayoutContext
|
|
6
6
|
* @output Unit tests for Field component behavior
|
|
7
7
|
* @position Testing; validates Field.tsx implementation
|
|
8
8
|
*
|
|
@@ -10,11 +10,18 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import {describe, it, expect, vi, afterEach} from 'vitest';
|
|
13
|
-
import {render, screen, waitFor} from '@testing-library/react';
|
|
13
|
+
import {render, screen, waitFor, fireEvent} from '@testing-library/react';
|
|
14
|
+
import * as stylex from '@stylexjs/stylex';
|
|
14
15
|
import {Field} from './Field';
|
|
15
16
|
import {FormLayoutContext} from '../FormLayout/FormLayoutContext';
|
|
16
17
|
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
|
|
17
18
|
|
|
19
|
+
const testStyles = stylex.create({
|
|
20
|
+
root: {
|
|
21
|
+
minWidth: '123px',
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
18
25
|
function politeRegion(): HTMLElement | null {
|
|
19
26
|
return document.querySelector('[data-astryx-live-region="polite"]');
|
|
20
27
|
}
|
|
@@ -572,6 +579,57 @@ describe('Field', () => {
|
|
|
572
579
|
</FormLayoutContext>
|
|
573
580
|
);
|
|
574
581
|
|
|
582
|
+
it('composes root props without letting callers replace layout semantics', () => {
|
|
583
|
+
const onClick = vi.fn();
|
|
584
|
+
const expectedXstyleClass = stylex.props(testStyles.root).className;
|
|
585
|
+
if (expectedXstyleClass == null) {
|
|
586
|
+
throw new Error('Expected the test xstyle to produce a class name.');
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
render(
|
|
590
|
+
<Field
|
|
591
|
+
label="Name"
|
|
592
|
+
inputID="name-input"
|
|
593
|
+
data-testid="field"
|
|
594
|
+
data-layout="consumer"
|
|
595
|
+
data-owner="consumer"
|
|
596
|
+
className="consumer-class"
|
|
597
|
+
style={{width: '321px'}}
|
|
598
|
+
xstyle={testStyles.root}
|
|
599
|
+
onClick={onClick}>
|
|
600
|
+
<input id="name-input" />
|
|
601
|
+
</Field>,
|
|
602
|
+
{wrapper: horizontalLabelsWrapper},
|
|
603
|
+
);
|
|
604
|
+
|
|
605
|
+
const field = screen.getByTestId('field');
|
|
606
|
+
expect(field).toHaveClass('astryx-field', 'consumer-class');
|
|
607
|
+
expect(field).toHaveClass(expectedXstyleClass);
|
|
608
|
+
expect(field).toHaveAttribute('data-layout', 'horizontal-labels');
|
|
609
|
+
expect(field).toHaveAttribute('data-owner', 'consumer');
|
|
610
|
+
expect(field).toHaveStyle({width: '321px'});
|
|
611
|
+
fireEvent.click(field);
|
|
612
|
+
expect(onClick).toHaveBeenCalledOnce();
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
it('visually hides the description in horizontal-label mode when the label is hidden', () => {
|
|
616
|
+
render(
|
|
617
|
+
<Field
|
|
618
|
+
label="Search"
|
|
619
|
+
inputID="search-input"
|
|
620
|
+
isLabelHidden
|
|
621
|
+
description="Search for items"
|
|
622
|
+
descriptionID="search-desc">
|
|
623
|
+
<input id="search-input" aria-describedby="search-desc" />
|
|
624
|
+
</Field>,
|
|
625
|
+
{wrapper: horizontalLabelsWrapper},
|
|
626
|
+
);
|
|
627
|
+
|
|
628
|
+
const description = screen.getByText('Search for items');
|
|
629
|
+
expect(description.className).toContain('visuallyHidden');
|
|
630
|
+
expect(description).toHaveAttribute('id', 'search-desc');
|
|
631
|
+
});
|
|
632
|
+
|
|
575
633
|
it('applies display:contents when in horizontal-labels context', () => {
|
|
576
634
|
const {container} = render(
|
|
577
635
|
<Field label="Name" inputID="name-input">
|
package/src/Field/Field.tsx
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @file Field.tsx
|
|
7
|
-
* @input Uses React,
|
|
7
|
+
* @input Uses React, StyleX, BaseProps, FieldLabel/FieldStatus, FormLayoutContext, Text, VisuallyHidden, theme/status utilities
|
|
8
8
|
* @output Exports Field component, FieldProps
|
|
9
9
|
* @position Core implementation; consumed by index.ts, tested by Field.test.tsx
|
|
10
10
|
*
|
|
@@ -30,6 +30,7 @@ import {mergeProps} from '../utils';
|
|
|
30
30
|
import {useDevWarning} from '../hooks/useDevWarning';
|
|
31
31
|
import {FormLayoutContext} from '../FormLayout/FormLayoutContext';
|
|
32
32
|
import {Text} from '../Text';
|
|
33
|
+
import {VisuallyHidden} from '../VisuallyHidden';
|
|
33
34
|
import {themeProps} from '../utils/themeProps';
|
|
34
35
|
|
|
35
36
|
const styles = stylex.create({
|
|
@@ -298,20 +299,28 @@ export function Field({
|
|
|
298
299
|
return (
|
|
299
300
|
<div
|
|
300
301
|
ref={ref}
|
|
302
|
+
{...props}
|
|
301
303
|
{...mergeProps(
|
|
302
304
|
themeProps('field', {layout: 'horizontal-labels'}),
|
|
303
305
|
stylex.props(styles.horizontalLabels, xstyle),
|
|
304
306
|
className,
|
|
305
307
|
style,
|
|
306
|
-
)}
|
|
307
|
-
{...props}>
|
|
308
|
+
)}>
|
|
308
309
|
<div {...stylex.props(styles.horizontalLabelAlign)}>{labelNode}</div>
|
|
309
310
|
<div {...stylex.props(styles.inputStatusWrapper)}>
|
|
310
|
-
{description &&
|
|
311
|
-
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
|
|
311
|
+
{description &&
|
|
312
|
+
(isLabelHidden ? (
|
|
313
|
+
<VisuallyHidden id={resolvedDescriptionID}>
|
|
314
|
+
{description}
|
|
315
|
+
</VisuallyHidden>
|
|
316
|
+
) : (
|
|
317
|
+
<Text
|
|
318
|
+
type="supporting"
|
|
319
|
+
display="block"
|
|
320
|
+
id={resolvedDescriptionID}>
|
|
321
|
+
{description}
|
|
322
|
+
</Text>
|
|
323
|
+
))}
|
|
315
324
|
{children}
|
|
316
325
|
{statusNode}
|
|
317
326
|
</div>
|
package/src/Grid/GridSpan.tsx
CHANGED
|
@@ -47,6 +47,9 @@ const baseStyles = stylex.create({
|
|
|
47
47
|
minWidth: 0, // Prevent overflow in grid
|
|
48
48
|
// Make span fill grid cell and stretch children
|
|
49
49
|
display: 'grid',
|
|
50
|
+
// The implicit `auto` column would grow to a child's min-content width;
|
|
51
|
+
// a zero minimum keeps it inside the span.
|
|
52
|
+
gridTemplateColumns: 'minmax(0, 1fr)',
|
|
50
53
|
height: '100%',
|
|
51
54
|
},
|
|
52
55
|
});
|
|
@@ -43,8 +43,8 @@ export const docs = {
|
|
|
43
43
|
{
|
|
44
44
|
name: 'label',
|
|
45
45
|
type: "{ position?: 'start' | 'top', width?: number | string }",
|
|
46
|
-
description: "Label display configuration. position controls label placement, width sets a custom label column width. Defaults to { position: 'top' } for multi-column layouts.",
|
|
47
|
-
default: "{ position: 'start' } (single-column) / { position: 'top' } (multi-column)",
|
|
46
|
+
description: "Label display configuration. position controls label placement, width sets a custom label column width. Defaults to { position: 'top' } for multi-column layouts. Position is ignored in horizontal mode, which always uses { position: 'top' }.",
|
|
47
|
+
default: "{ position: 'start' } (vertical single-column) / { position: 'top' } (multi-column or horizontal)",
|
|
48
48
|
},
|
|
49
49
|
{
|
|
50
50
|
name: 'maxNumOfItems',
|
|
@@ -124,6 +124,30 @@ describe('MetadataList', () => {
|
|
|
124
124
|
expect(screen.getByText('B')).toBeInTheDocument();
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
+
it('uses top labels in horizontal orientation even when position is start', () => {
|
|
128
|
+
render(
|
|
129
|
+
<MetadataList orientation="horizontal" label={{position: 'start'}}>
|
|
130
|
+
<MetadataListItem label="A">1</MetadataListItem>
|
|
131
|
+
</MetadataList>,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const item = screen.getByRole('term').closest('.astryx-metadata-list-item');
|
|
135
|
+
expect(item).toContainElement(screen.getByRole('definition'));
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('defaults to side labels and preserves width when position is omitted', () => {
|
|
139
|
+
const {container} = render(
|
|
140
|
+
<MetadataList label={{width: 120}}>
|
|
141
|
+
<MetadataListItem label="A">1</MetadataListItem>
|
|
142
|
+
</MetadataList>,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
const list = container.querySelector('dl');
|
|
146
|
+
expect(list?.getAttribute('style')).toContain('120px minmax(0, 1fr)');
|
|
147
|
+
expect(screen.getByRole('term').parentElement).toBe(list);
|
|
148
|
+
expect(screen.getByRole('definition').parentElement).toBe(list);
|
|
149
|
+
});
|
|
150
|
+
|
|
127
151
|
describe('numeric columns', () => {
|
|
128
152
|
// A fixed column count is a runtime value, so it arrives as a StyleX
|
|
129
153
|
// dynamic style: the template lands in the element's inline style (as the
|
|
@@ -163,6 +187,20 @@ describe('MetadataList', () => {
|
|
|
163
187
|
expect(gridTemplateOf(container)).not.toContain('repeat(');
|
|
164
188
|
});
|
|
165
189
|
|
|
190
|
+
it('defaults to top labels for columns={2} with a width-only label config', () => {
|
|
191
|
+
const {container} = render(
|
|
192
|
+
<MetadataList columns={2} label={{width: 260}}>
|
|
193
|
+
<MetadataListItem label="A">1</MetadataListItem>
|
|
194
|
+
</MetadataList>,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
expect(gridTemplateOf(container)).toContain('repeat(2, 1fr)');
|
|
198
|
+
const item = screen
|
|
199
|
+
.getByRole('term')
|
|
200
|
+
.closest('.astryx-metadata-list-item');
|
|
201
|
+
expect(item).toContainElement(screen.getByRole('definition'));
|
|
202
|
+
});
|
|
203
|
+
|
|
166
204
|
it('ignores numeric columns in horizontal orientation', () => {
|
|
167
205
|
const {container} = render(
|
|
168
206
|
<MetadataList columns={3} orientation="horizontal">
|
|
@@ -206,7 +206,14 @@ export function MetadataList({
|
|
|
206
206
|
columns === 'multi' || (typeof columns === 'number' && columns > 1);
|
|
207
207
|
// Default to 'top' for multi-column and horizontal layouts since side labels
|
|
208
208
|
// don't work well when items are in separate grid cells.
|
|
209
|
-
const
|
|
209
|
+
const defaultLabelConfig = isMultiColumn ? LABEL_TOP : LABEL_START;
|
|
210
|
+
const labelConfig = useMemo(
|
|
211
|
+
() => ({
|
|
212
|
+
...label,
|
|
213
|
+
position: label?.position ?? defaultLabelConfig.position,
|
|
214
|
+
}),
|
|
215
|
+
[label, defaultLabelConfig],
|
|
216
|
+
);
|
|
210
217
|
const [isShowAll, setIsShowAll] = useState(false);
|
|
211
218
|
const contentId = useId();
|
|
212
219
|
const t = useTranslator();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
2
|
|
|
3
|
-
import {describe, it} from 'vitest';
|
|
4
|
-
import {screen} from '@testing-library/react';
|
|
3
|
+
import {describe, it, expect} from 'vitest';
|
|
4
|
+
import {render, screen} from '@testing-library/react';
|
|
5
5
|
import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';
|
|
6
6
|
import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';
|
|
7
7
|
import {RadioList, type RadioListProps} from './RadioList';
|
|
@@ -22,3 +22,46 @@ describeFieldInputParts('RadioList', {
|
|
|
22
22
|
getControl: () => screen.getByRole('radiogroup'),
|
|
23
23
|
inGroup: false,
|
|
24
24
|
});
|
|
25
|
+
|
|
26
|
+
describe('RadioList FR10 details', () => {
|
|
27
|
+
it("names the radiogroup by its label and then a caller's aria-labelledby", () => {
|
|
28
|
+
render(
|
|
29
|
+
<>
|
|
30
|
+
<span id="caller-name">Billing</span>
|
|
31
|
+
<RadioList
|
|
32
|
+
label="Plan"
|
|
33
|
+
value="a"
|
|
34
|
+
onChange={() => {}}
|
|
35
|
+
aria-labelledby="caller-name">
|
|
36
|
+
<RadioListItem label="A" value="a" />
|
|
37
|
+
</RadioList>
|
|
38
|
+
</>,
|
|
39
|
+
);
|
|
40
|
+
const group = screen.getByRole('radiogroup');
|
|
41
|
+
const ids = group.getAttribute('aria-labelledby')?.split(' ');
|
|
42
|
+
expect(ids).toHaveLength(2);
|
|
43
|
+
expect(document.getElementById(ids?.[0] ?? '')?.textContent).toContain(
|
|
44
|
+
'Plan',
|
|
45
|
+
);
|
|
46
|
+
expect(ids?.[1]).toBe('caller-name');
|
|
47
|
+
expect(screen.getByRole('radiogroup', {name: 'Plan Billing'})).toBe(group);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('puts hidden, inert, and dir on the radiogroup', () => {
|
|
51
|
+
render(
|
|
52
|
+
<RadioList
|
|
53
|
+
label="Plan"
|
|
54
|
+
value="a"
|
|
55
|
+
onChange={() => {}}
|
|
56
|
+
hidden
|
|
57
|
+
inert
|
|
58
|
+
dir="rtl">
|
|
59
|
+
<RadioListItem label="A" value="a" />
|
|
60
|
+
</RadioList>,
|
|
61
|
+
);
|
|
62
|
+
const group = document.querySelector<HTMLElement>('[role="radiogroup"]');
|
|
63
|
+
expect(group).toHaveAttribute('hidden');
|
|
64
|
+
expect(group).toHaveAttribute('inert');
|
|
65
|
+
expect(group).toHaveAttribute('dir', 'rtl');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -31,6 +31,7 @@ import type {InputStatus} from '../Field/types';
|
|
|
31
31
|
import {useTooltip} from '../Tooltip';
|
|
32
32
|
import {useResolvedRequired} from '../hooks/useResolvedRequired';
|
|
33
33
|
import {composeEventHandlers, mergeProps} from '../utils';
|
|
34
|
+
import {joinAriaIDs} from '../utils/inputAria';
|
|
34
35
|
import {
|
|
35
36
|
type FieldInputBaseProps,
|
|
36
37
|
useFieldInputStyling,
|
|
@@ -216,6 +217,7 @@ export function RadioList({
|
|
|
216
217
|
htmlName,
|
|
217
218
|
children,
|
|
218
219
|
onFocus,
|
|
220
|
+
'aria-labelledby': ariaLabelledByProp,
|
|
219
221
|
'aria-describedby': ariaDescribedByProp,
|
|
220
222
|
...restProps
|
|
221
223
|
}: RadioListProps) {
|
|
@@ -399,7 +401,8 @@ export function RadioList({
|
|
|
399
401
|
disabledMessageTooltip.ref(el);
|
|
400
402
|
}}
|
|
401
403
|
role="radiogroup"
|
|
402
|
-
aria-labelledby
|
|
404
|
+
// A caller aria-labelledby names the group together with its label.
|
|
405
|
+
aria-labelledby={joinAriaIDs(labelID, ariaLabelledByProp)}
|
|
403
406
|
onFocus={composeEventHandlers(handleFocus, onFocus)}
|
|
404
407
|
aria-describedby={
|
|
405
408
|
[
|