Skip to content

Commit

Permalink
fix(sbb-checkbox, sbb-checkbox-panel): fix visual disabled state afte…
Browse files Browse the repository at this point in the history
…r prop change
  • Loading branch information
jeripeierSBB committed Jul 8, 2024
1 parent a8b26ff commit e07c1fa
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
49 changes: 45 additions & 4 deletions src/elements/checkbox/common/checkbox-common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ describe(`checkbox common behaviors`, () => {
focusable: false,
});

if (selector === 'sbb-checkbox-panel') {
if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
Expand All @@ -591,7 +591,7 @@ describe(`checkbox common behaviors`, () => {
focusable: false,
});

if (selector === 'sbb-checkbox-panel') {
if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
Expand All @@ -615,7 +615,7 @@ describe(`checkbox common behaviors`, () => {
focusable: true,
});

if (selector === 'sbb-checkbox-panel') {
if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
Expand All @@ -638,7 +638,8 @@ describe(`checkbox common behaviors`, () => {
ariaDisabled: undefined,
focusable: true,
});
if (selector === 'sbb-checkbox-panel') {

if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
Expand All @@ -659,6 +660,14 @@ describe(`checkbox common behaviors`, () => {
focusable: false,
});

if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
)!.disabled,
).to.be.true;
}

element.toggleAttribute('disabled', false);
await waitForLitRender(form);

Expand All @@ -669,6 +678,14 @@ describe(`checkbox common behaviors`, () => {
ariaDisabled: undefined,
focusable: true,
});

if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
)!.disabled,
).to.be.false;
}
});

it('should be disabled by property', async () => {
Expand All @@ -683,6 +700,14 @@ describe(`checkbox common behaviors`, () => {
focusable: false,
});

if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
)!.disabled,
).to.be.true;
}

element.disabled = false;
await waitForLitRender(form);

Expand All @@ -693,6 +718,14 @@ describe(`checkbox common behaviors`, () => {
ariaDisabled: undefined,
focusable: true,
});

if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
)!.disabled,
).to.be.false;
}
});

it('should sync disabled attribute after re-enabling by property', async () => {
Expand All @@ -709,6 +742,14 @@ describe(`checkbox common behaviors`, () => {
ariaDisabled: undefined,
focusable: true,
});

if (selector !== 'input') {
expect(
element.shadowRoot!.querySelector<SbbVisualCheckboxElement>(
'sbb-visual-checkbox',
)!.disabled,
).to.be.false;
}
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion src/elements/core/mixins/form-associated-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,12 @@ export const SbbFormAssociatedMixin = <T extends Constructor<LitElement>>(
* @internal
*/
public formDisabledCallback(disabled: boolean): void {
this.formDisabled = disabled;
// This callback is triggered if the disabled property changes or the disabled attribute of a fieldset or form changes.
// We need to postpone the assignment, otherwise it interferes with disabled status setting
// and leads to a wrong state (e.g. embedded sbb-visual-checkbox).
Promise.resolve().then(() => {
this.formDisabled = disabled;
});
}

/**
Expand Down

0 comments on commit e07c1fa

Please sign in to comment.