deterministic + unique ids in 6 components (node-derived scope)
Migrates Menu, ColumnLayout, Countdown, Gallery, Tabs, InputField, and
TextareaField from Math.random()/content-hash scope ids to the threaded
Craft node id (via scopeId()), keeping every emitted element id,
aria-controls/aria-labelledby/for, and inline <script> function
name/getElementById() call consistently scoped per component.
Resolves the two Important id-collision review findings:
- Tabs: tabId was djb2(anchorId||labels) -- two default Tabs instances
produced identical aria-controls/aria-labelledby ids, so one instance's
arrow-key script clobbered the other's tab/panel wiring.
- InputField/TextareaField: fieldId was `field-${name}` -- two fields
sharing a (often default) name produced duplicate <label for>/<input
id> pairs, breaking the for/id association for one of them.
Also eliminates the remaining Math.random() scope ids in Menu (hover CSS
class scope) and ColumnLayout (nth-child width CSS class scope), so no
export component is non-deterministic anymore.
All fall back to a stable content hash (never Math.random) for legacy
2-arg toHtml() call sites without a node id.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,3 +19,34 @@ describe('TextareaField.toHtml accessibility (F2.1)', () => {
|
||||
expect(html).toContain('aria-label="Anything else?"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('TextareaField.toHtml deterministic + unique ids (thread node id, resolves id-collision finding)', () => {
|
||||
test('label for= still matches textarea id= after threading the node id', () => {
|
||||
const { html } = toHtml({ label: 'Message', name: 'message' }, '', 'node-ta1');
|
||||
const forMatch = html.match(/<label for="([^"]+)"/);
|
||||
const idMatch = html.match(/<textarea id="([^"]+)"/);
|
||||
expect(forMatch![1]).toBe(idMatch![1]);
|
||||
});
|
||||
|
||||
test('same node id -> identical output across calls (deterministic, no Math.random)', () => {
|
||||
const { html: html1 } = toHtml({ label: 'Message', name: 'message' }, '', 'node-ta1');
|
||||
const { html: html2 } = toHtml({ label: 'Message', name: 'message' }, '', 'node-ta1');
|
||||
expect(html1).toBe(html2);
|
||||
});
|
||||
|
||||
test('two instances with the SAME default name but different node ids do not collide', () => {
|
||||
const { html: html1 } = toHtml({ label: 'Message', name: 'message' }, '', 'node-ta1');
|
||||
const { html: html2 } = toHtml({ label: 'Message', name: 'message' }, '', 'node-ta2');
|
||||
const id1 = html1.match(/<textarea id="([^"]+)"/)![1];
|
||||
const id2 = html2.match(/<textarea id="([^"]+)"/)![1];
|
||||
expect(id1).not.toBe(id2);
|
||||
});
|
||||
|
||||
test('no nodeId (legacy 2-arg call): id derivation stays deterministic, not random', () => {
|
||||
const { html: html1 } = toHtml({ label: 'Message', name: 'message' }, '');
|
||||
const { html: html2 } = toHtml({ label: 'Message', name: 'message' }, '');
|
||||
const id1 = html1.match(/<textarea id="([^"]+)"/)![1];
|
||||
const id2 = html2.match(/<textarea id="([^"]+)"/)![1];
|
||||
expect(id1).toBe(id2);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user