Skip to content

Commit

Permalink
refactor(selection-panel): now only reacts to main input changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMenga committed Jan 22, 2024
1 parent 54ddc84 commit b74eacb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/components/checkbox/checkbox/checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ export class SbbCheckboxElement extends UpdateScheduler(LitElement) {
}
private _size: SbbCheckboxSize = 'm';

/** Whether the input is the main input of a selection panel. */
/**
* Whether the input is the main input of a selection panel.
* @internal
*/
public get isSelectionPanelInput(): boolean {
return this._isSelectionPanelInput;
}
@state() private _isSelectionPanelInput = false;

/** The label describing whether the selection panel is expanded (for screen readers only). */
Expand Down
5 changes: 5 additions & 0 deletions src/components/radio-button/radio-button/radio-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export class SbbRadioButtonElement extends UpdateScheduler(LitElement) {

/**
* Whether the input is the main input of a selection panel.
* @internal
*/
public get isSelectionPanelInput(): boolean {
return this._isSelectionPanelInput;
}
@state() private _isSelectionPanelInput = false;

/**
Expand Down Expand Up @@ -150,6 +154,7 @@ export class SbbRadioButtonElement extends UpdateScheduler(LitElement) {

private _handleCheckedChange(currentValue: boolean, previousValue: boolean): void {
if (currentValue !== previousValue) {
console.log('checked change');
this._stateChange.emit({ type: 'checked', checked: currentValue });
this._isSelectionPanelInput && this._updateExpandedLabel();
}
Expand Down
13 changes: 12 additions & 1 deletion src/components/selection-panel/selection-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export class SbbSelectionPanelElement extends LitElement {

private _initFromInput(event: Event): void {
const input = event.target as SbbCheckboxElement | SbbRadioButtonElement;

if (!input.isSelectionPanelInput) {
return;
}

this._checked = input.checked;
this._disabled = input.disabled;
this._updateState();
Expand All @@ -154,6 +159,12 @@ export class SbbSelectionPanelElement extends LitElement {
private _onInputStateChange(
event: CustomEvent<SbbRadioButtonStateChange | SbbCheckboxStateChange>,
): void {
const input = event.target as SbbCheckboxElement | SbbRadioButtonElement;

if (!input.isSelectionPanelInput) {
return;
}

if (event.detail.type === 'disabled') {
this._disabled = event.detail.disabled;
return;
Expand Down Expand Up @@ -191,7 +202,7 @@ export class SbbSelectionPanelElement extends LitElement {
</div>
<div
class="sbb-selection-panel__content--wrapper"
.inert="${!this._checked && !this.forceOpen};"
.inert=${this._state !== 'opened'}
@animationend=${(event: AnimationEvent) => this._onAnimationEnd(event)}
>
<div class="sbb-selection-panel__content">
Expand Down

0 comments on commit b74eacb

Please sign in to comment.