Skip to content

Commit 760550c

Browse files
committed
feat(core): a first-party indicator can paint its own press
CheckboxInput paints its press over a replacement indicator as a rounded square, which tints past a round indicator such as a circle. It now leaves that layer off over an indicator that applies `indicatorPressScope`, an internal marker for Astryx's own replacement indicators (`@astryxdesign/core/internal/indicatorPress.stylex`, not public API). The row also hands its touch press image down as `--_indicator-press-image`, because an indicator in another package may not name the row's private press attribute. Only the row declares it, so an indicator mapped into a row that paints its own press, such as a menu's checkbox item, paints nothing twice. Hover and a mouse press reach the indicator through the row's scope marker, as for the built-in indicator. Indicators without the marker are unchanged. component:CheckboxInput AV1 and FR11 now say so: a first-party replacement indicator may paint its own press from the row's hover and press, while CheckboxInput still paints focus. The unit cases that read the injected rules fail on main: the row hands its touch press image down, and the press layer turns off over a marked indicator. A disabled row hands nothing down. A unit case keeps the marker off every public entry and the API report.
1 parent bf14580 commit 760550c

9 files changed

Lines changed: 186 additions & 15 deletions

File tree

‎.changeset/indicator-own-press.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/core': patch
3+
---
4+
5+
[feat] CheckboxInput can leave its rounded-square press layer off over a first-party replacement indicator that paints its own press. Indicators in this release are unchanged.
6+
7+
@vjeux

‎docs/specs/components/CheckboxInput/CheckboxInput.spec.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ system_specs: [spec:AST-021, spec:AST-085, spec:AST-086]
5252
| Area | Contract |
5353
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5454
| Public contract | `CheckboxInput` is a controlled native checkbox with a required `label` and `value`; it supports synchronous and transition-backed change handlers, loading, disabled, disabled-reason, read-only, validation, sizing, and field content. |
55-
| Behavior | The native input owns role, state, focus, form participation, and activation. A replaceable CheckboxIndicator owns the visible box while CheckboxInput owns its focus ring and pressed overlay. |
55+
| Behavior | The native input owns role, state, focus, form participation, and activation. A replaceable CheckboxIndicator owns the visible box while CheckboxInput owns its focus ring and pressed overlay, except where a first-party indicator paints its own press (AV1). |
5656
| End-user impact | People can identify and operate available choices, review inert values as read-only, discover disabled reasons from the keyboard, and perceive busy, validation, focus, and pressed states. |
5757
| Builder impact | None. Builders control the value and may use `onChange`, `changeAction`, or both; the meaning of omitting both stays an open question (OQ1). |
5858
| Compatibility/readiness | Records shipped behavior; no API, default, or DOM change. A handlerless checkbox declares no read-only state, a mixed value can lose its native mixed state on activation, and caller key handlers run while disabled; all are listed under Current-state impact. |
@@ -79,7 +79,7 @@ Consumer migration instructions belong in consumer docs and release notes.
7979
**Owns**
8080

8181
- Native checkbox role, checked/mixed state, label, description/status relationships, focus, activation, availability, read-only state, required/invalid/busy state, and form participation.
82-
- Composition of the resolved checkbox indicator, owner-painted focus ring and pressed overlay, disabled-reason tooltip, field label, description, and detached status.
82+
- Composition of the resolved checkbox indicator, owner-painted focus ring and pressed overlay (except where a first-party indicator paints its own press; AV1), disabled-reason tooltip, field label, description, and detached status.
8383
- Ordering between `onChange`, `preventDefault`, optimistic pending state, and `changeAction`.
8484

8585
**Does not own / non-goals**
@@ -115,13 +115,13 @@ Consumer migration instructions belong in consumer docs and release notes.
115115
| FR8 | Caller DOM props MUST reach the input, while component-owned type, checked, disabled, read-only, required, busy, invalid, description, ref, and styling values retain precedence. | `architecture:public-component-api/INV5–INV8`; component tests |
116116
| FR9 | The outer field MUST retain `checkbox-input`, the label MUST retain `checkbox-label`, and the built-in CheckboxIndicator path MUST retain its canonical targets. Replacement indicators are not required to accept target classes. | source/docs target inventory; replacement component tests; `architecture:component-theming-surface/INV4–INV8,INV12` |
117117
| FR10 | Keyboard/programmatic focus on the hidden native input MUST paint the shared focus-visible outline on the resolved indicator element, including a replacement indicator that forwards no props. | `architecture:interaction-modality/INV1–INV3`; component tests |
118-
| FR11 | CheckboxInput applies `design:user-states` DR1 and DR2 for the pressed overlay, painting it on the indicator while the row is pressed. | `design:user-states/DR1–DR5` |
118+
| FR11 | CheckboxInput applies `design:user-states` DR1 and DR2 for the pressed overlay, painting it on the indicator while the row is pressed, except over an indicator that paints its own press (AV1). | `design:user-states/DR1–DR5` |
119119
| FR12 | `sm` and `md` MUST keep the native input, indicator, focus paint, and row geometry aligned; field `width` MUST size the whole field rather than only the input. | shipped source, tests, and stories |
120120
| FR13 | With neither `onChange` nor `changeAction`, activation changes nothing the caller can observe. Implementation gap: the checkbox declares no read-only or unavailable state; its meaning is OQ1 (Current-state impact). | shared checkbox known-failure record |
121121

122122
### Allowed variation
123123

124-
- **AV1 — Indicator replacement.** A theme may replace the named checkbox indicator if it preserves the Indicator prop and decorative ownership contracts; CheckboxInput still paints focus and pressed feedback on the resolved root.
124+
- **AV1 — Indicator replacement.** A theme may replace the named checkbox indicator if it preserves the Indicator prop and decorative ownership contracts; CheckboxInput still paints focus and pressed feedback on the resolved root. The one exception: a first-party replacement indicator may paint its own press from the row's hover and press (an internal marker; not public API), while CheckboxInput still paints focus.
125125
- **AV2 — Theme paint.** Canonical component targets and semantic tokens may change admitted visual properties without changing native semantics, state precedence, or interaction ownership.
126126
- **AV3 — Caller field content.** Label, description, status text, icon/content, and width may vary within their public types.
127127

@@ -187,7 +187,7 @@ The consumer record includes composed targets owned by CheckboxIndicator, FieldL
187187
| FR8 | `CheckboxInput.test.tsx` passthrough, id, ref, and rest-precedence cases | Caller `id`, `data-*`, ref | A caller prop overriding `checked`, `disabled`, or `type` fails. | `audit:CheckboxInput/api` |
188188
| FR9 | `CheckboxInput.test.tsx` label-target case; `themingTargets.test.ts` | Label; built-in indicator | A missing label target, or a rendered class absent from the documented targets, fails. Evidence gap: no test asserts the root `checkbox-input` target. | `audit:CheckboxInput/theming` |
189189
| FR10, AR3 | `CheckboxInput.test.tsx` focus-ring ownership suite | Built-in and prop-dropping replacement indicators; blur | A ring on the wrong element, or none, fails. | `audit:CheckboxInput/a11y` |
190-
| FR11 | `CheckboxInput.test.tsx` pressed-state suite | Enabled press; disabled; touch fade | A missing overlay, or one on a disabled box, fails. | `audit:CheckboxInput/visual` |
190+
| FR11 | `CheckboxInput.test.tsx` pressed-state suite and its suite for an indicator that paints its own press | Enabled press; disabled; touch fade | A missing overlay, or one on a disabled box, fails. | `audit:CheckboxInput/visual` |
191191
| FR12, AR5 | `CheckboxInput.test.tsx` coarse-pointer, RTL, and forced-colors suites | `sm`, `md`; RTL; forced colors | A misplaced hit target or a mark lost in forced colors fails. Evidence gap: no test asserts field `width`. | `audit:CheckboxInput/layout` |
192192
| ORD1–ORD4, PR1 | ORD4 is covered by the FR8 rest-precedence case and ORD3 by the shared accessibility suite's disabled, disabled-reason, and read-only states. Evidence gap: no test asserts the optimistic value between `value` and the indicator (ORD1), the `preventDefault` check before `changeAction` (ORD2), or the absence of global listeners | — | — | `audit:CheckboxInput/behavior` |
193193

‎packages/core/package.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,11 @@
833833
"source": "./src/internal/touch-sheet.ts",
834834
"types": "./dist/internal/touch-sheet.d.ts",
835835
"default": "./dist/internal/touch-sheet.js"
836+
},
837+
"./internal/indicatorPress.stylex": {
838+
"source": "./src/internal/indicatorPress.stylex.ts",
839+
"types": "./dist/internal/indicatorPress.stylex.d.ts",
840+
"default": "./dist/internal/indicatorPress.stylex.js"
836841
}
837842
},
838843
"files": [

‎packages/core/src/CheckboxInput/CheckboxInput.doc.mjs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ export const docs = {
151151
},
152152
{className: 'astryx-checkbox-label'},
153153
],
154+
vars: [
155+
{
156+
name: '--_indicator-press-image',
157+
description:
158+
"The row's touch press image, handed down to a first-party indicator that paints its own press. Set from the press paint only while the row itself is pressed; only this row declares it.",
159+
default: 'none',
160+
private: true,
161+
},
162+
],
154163
},
155164
usage: {
156165
accessibility: [
@@ -390,6 +399,15 @@ export const docsZh = {
390399
},
391400
{className: 'astryx-checkbox-label'},
392401
],
402+
vars: [
403+
{
404+
name: '--_indicator-press-image',
405+
description:
406+
'复选框行的触摸按下图像,传递给自行绘制按下效果的第一方指示器。仅在该行自身被按下时根据按下涂层设置,只有该行声明它。',
407+
default: 'none',
408+
private: true,
409+
},
410+
],
393411
},
394412
};
395413

‎packages/core/src/CheckboxInput/CheckboxInput.test.tsx‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
* SYNC: When CheckboxInput.tsx changes, update tests to match new behavior
1313
*/
1414

15+
import {readFileSync} from 'node:fs';
1516
import {describe, it, expect, vi, beforeEach, afterEach} from 'vitest';
1617
import {render, screen, fireEvent, waitFor} from '@testing-library/react';
1718
import userEvent from '@testing-library/user-event';
1819
import {
1920
hasPressedArm,
2021
hasReleaseFade,
2122
readsPressStrength,
23+
rulesDeclaredFor,
24+
rulesWithSelector,
2225
} from '../__tests__/pressState';
2326
import {CheckboxInput} from './CheckboxInput';
27+
import * as publicMarkers from '../Indicator/indicator.markers.stylex';
2428
import {Theme} from '../theme/Theme';
2529
import {defineTheme} from '../theme/defineTheme';
2630
import {getForcedColorsRules} from '../__tests__/forcedColors';
@@ -924,3 +928,83 @@ describe('pressed state', () => {
924928
expect(readsPressStrength(wrapper)).toBe(true);
925929
});
926930
});
931+
932+
describe('an indicator that paints its own press', () => {
933+
it('keeps its marker internal: no public entry exports it, and the API report has no row', () => {
934+
expect(Object.keys(publicMarkers)).not.toContain('indicatorPressScope');
935+
const report = readFileSync('packages/core/api-report.md', 'utf8');
936+
expect(report).not.toContain('indicatorPressScope');
937+
});
938+
939+
const partsOf = (container: HTMLElement) => {
940+
const box = container.querySelector('.astryx-checkbox-indicator');
941+
const wrapper = box?.parentElement?.parentElement;
942+
const row = wrapper?.parentElement;
943+
if (wrapper == null || row == null) {
944+
throw new Error('the checkbox has no indicator wrapper or row');
945+
}
946+
return {wrapper, row};
947+
};
948+
949+
it('hands its touch press image down only in its own press states, as a private property only the row declares', () => {
950+
const {container} = render(
951+
<CheckboxInput label="Accept terms" value={false} onChange={() => {}} />,
952+
);
953+
const {row} = partsOf(container);
954+
const rules = rulesDeclaredFor(row).filter(rule =>
955+
rule.includes('--_indicator-press-image'),
956+
);
957+
const handing = rules.filter(rule =>
958+
/--_indicator-press-image:\s*var\(--_press-paint-image\)/.test(rule),
959+
);
960+
expect(handing.length).toBeGreaterThan(0);
961+
// A pressed ancestor row hands nothing down: only the row's own states do.
962+
expect(
963+
handing.every(rule => /\[data-astryx-press="(on|fading)"\]/.test(rule)),
964+
).toBe(true);
965+
// No default of its own: a layered stylesheet ranks a default above arms.
966+
expect(
967+
rules.every(rule => /\[data-astryx-press="(on|fading)"\]/.test(rule)),
968+
).toBe(true);
969+
});
970+
971+
it('hands nothing down from a disabled checkbox', () => {
972+
const {container} = render(
973+
<CheckboxInput
974+
label="Unavailable"
975+
value={false}
976+
onChange={() => {}}
977+
isDisabled
978+
/>,
979+
);
980+
const {row} = partsOf(container);
981+
expect(
982+
rulesDeclaredFor(row).some(rule =>
983+
rule.includes('--_indicator-press-image'),
984+
),
985+
).toBe(false);
986+
});
987+
988+
it('leaves its rounded-square press layer off over an indicator marked as painting its own press', () => {
989+
const {container} = render(
990+
<CheckboxInput label="Accept terms" value={false} onChange={() => {}} />,
991+
);
992+
const {wrapper} = partsOf(container);
993+
// The layer reads the marked indicator as a descendant (`:has()`).
994+
const off = rulesWithSelector(wrapper, ':has(');
995+
expect(
996+
off.some(
997+
rule => rule.includes('::after') && /content:\s*none/.test(rule),
998+
),
999+
).toBe(true);
1000+
// Without such an indicator the layer stays on.
1001+
expect(
1002+
rulesDeclaredFor(wrapper).some(
1003+
rule =>
1004+
rule.includes('::after') &&
1005+
!rule.includes(':has(') &&
1006+
/content:\s*("")/.test(rule),
1007+
),
1008+
).toBe(true);
1009+
});
1010+
});

0 commit comments

Comments
 (0)