mirror of
https://github.com/material-components/material-web.git
synced 2026-01-09 07:21:09 +08:00
Merge pull request #5845 from austinw-fineart:patch-1
PiperOrigin-RevId: 804446918
This commit is contained in:
commit
834a1664ef
@ -74,15 +74,9 @@ export class SingleSelectionController implements ReactiveController {
|
||||
constructor(private readonly host: SingleSelectionElement) {}
|
||||
|
||||
hostConnected() {
|
||||
this.root = this.host.getRootNode() as ParentNode;
|
||||
this.host.addEventListener('keydown', this.handleKeyDown);
|
||||
this.host.addEventListener('focusin', this.handleFocusIn);
|
||||
this.host.addEventListener('focusout', this.handleFocusOut);
|
||||
if (this.host.checked) {
|
||||
// Uncheck other siblings when attached if already checked. This mimics
|
||||
// native <input type="radio"> behavior.
|
||||
this.uncheckSiblings();
|
||||
}
|
||||
|
||||
// Update siblings after a microtask to allow other synchronous connected
|
||||
// callbacks to settle before triggering additional Lit updates. This avoids
|
||||
@ -90,6 +84,13 @@ export class SingleSelectionController implements ReactiveController {
|
||||
// connected at the same time.
|
||||
queueMicrotask(() => {
|
||||
// Update for the newly added host.
|
||||
this.root = this.host.getRootNode() as ParentNode;
|
||||
if (this.host.checked) {
|
||||
// Uncheck other siblings when attached if already checked. This mimics
|
||||
// native <input type="radio"> behavior.
|
||||
this.uncheckSiblings();
|
||||
}
|
||||
|
||||
this.updateTabIndices();
|
||||
});
|
||||
}
|
||||
|
||||
@ -368,6 +368,7 @@ describe('<md-radio>', () => {
|
||||
// Connecting r1 shouldn't change anything, since it's the only one in the
|
||||
// group.
|
||||
container.appendChild(r1);
|
||||
await env.waitForStability();
|
||||
expect(r1.checked).toBeTrue();
|
||||
expect(r2.checked).toBeTrue();
|
||||
expect(r3.checked).toBeFalse();
|
||||
@ -375,12 +376,14 @@ describe('<md-radio>', () => {
|
||||
// Appending r2 should uncheck r1, because when a new checked radio is
|
||||
// connected, it wins (this matches native input behavior).
|
||||
container.appendChild(r2);
|
||||
await env.waitForStability();
|
||||
expect(r1.checked).toBeFalse();
|
||||
expect(r2.checked).toBeTrue();
|
||||
expect(r3.checked).toBeFalse();
|
||||
|
||||
// Appending r3 shouldn't change anything, because it's not checked.
|
||||
container.appendChild(r3);
|
||||
await env.waitForStability();
|
||||
expect(r1.checked).toBeFalse();
|
||||
expect(r2.checked).toBeTrue();
|
||||
expect(r3.checked).toBeFalse();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user