Skip to content

Commit

Permalink
fix: remove content logic for radio and fix badge docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeripeierSBB committed Jun 14, 2024
1 parent 9e94268 commit 2fc01d0
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 220 deletions.
10 changes: 3 additions & 7 deletions src/elements/checkbox/checkbox-group/checkbox-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ $breakpoints: 'zero', 'micro', 'small', 'medium', 'large', 'wide', 'ultra';
}
}

:host([data-has-selection-expansion-panel]) {
:host([data-has-panel]) {
--sbb-checkbox-group-width: 100%;

::slotted(sbb-checkbox-panel) {
flex: auto;
}
}

:host([data-has-selection-expansion-panel][orientation='vertical']) {
:host([data-has-panel][orientation='vertical']) {
--sbb-checkbox-group-gap: var(--sbb-spacing-fixed-2x) var(--sbb-spacing-fixed-4x);
}

Expand All @@ -53,11 +53,7 @@ $breakpoints: 'zero', 'micro', 'small', 'medium', 'large', 'wide', 'ultra';
}
}

:host(
[orientation='vertical'][horizontal-from='#{$breakpoint}']:not(
[data-has-selection-expansion-panel]
)
) {
:host([orientation='vertical'][horizontal-from='#{$breakpoint}']:not([data-has-panel])) {
--sbb-checkbox-group-width: max-content;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/elements/checkbox/checkbox-group/checkbox-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class SbbCheckboxGroupElement extends SbbDisabledMixin(LitElement) {
const signal = this._abort.signal;
this.addEventListener('keydown', (e) => this._handleKeyDown(e), { signal });
this.toggleAttribute(
'data-has-selection-expansion-panel',
'data-has-panel',
!!this.querySelector?.('sbb-selection-expansion-panel, sbb-checkbox-panel'),
);
}
Expand Down
6 changes: 5 additions & 1 deletion src/elements/checkbox/checkbox-panel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ The `sbb-checkbox-panel` component provides the same functionality as a native `

## Slots

It is possible to provide a label via an unnamed slot; additionally the slote named `subtext` can be used to provide a subtext and the slot named `suffix` can be used to provide suffix items.
It is possible to provide a label via an unnamed slot;
additionally the slots named `subtext` can be used to provide a subtext and
the slot named `suffix` can be used to provide suffix items.
If you use a <sbb-card-badge>, the slot `badge` is automatically assigned.

```html
<sbb-checkbox-panel>
<sbb-card-badge>%</sbb-card-badge>
Label
<span slot="subtext">Subtext</span>
<span slot="suffix">Suffix</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ $breakpoints: 'zero', 'micro', 'small', 'medium', 'large', 'wide', 'ultra';
}
}

:host([data-has-selection-expansion-panel]) {
:host([data-has-panel]) {
--sbb-radio-button-group-width: 100%;
}

:host([data-has-selection-expansion-panel][orientation='vertical']) {
:host([data-has-panel][orientation='vertical']) {
--sbb-radio-button-group-gap: var(--sbb-spacing-fixed-2x) var(--sbb-spacing-fixed-4x);
}

Expand All @@ -51,11 +51,7 @@ $breakpoints: 'zero', 'micro', 'small', 'medium', 'large', 'wide', 'ultra';
}
}

:host(
[orientation='vertical'][horizontal-from='#{$breakpoint}']:not(
[data-has-selection-expansion-panel]
)
) {
:host([orientation='vertical'][horizontal-from='#{$breakpoint}']:not([data-has-panel])) {
--sbb-radio-button-group-width: max-content;
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/elements/radio-button/radio-button-group/radio-button-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { hostAttributes } from '../../core/decorators.js';
import { EventEmitter } from '../../core/eventing.js';
import type { SbbHorizontalFrom, SbbOrientation, SbbStateChange } from '../../core/interfaces.js';
import { SbbDisabledMixin } from '../../core/mixins.js';
import type { SbbSelectionExpansionPanelElement } from '../../selection-expansion-panel.js';
import type { SbbRadioButtonSize, SbbRadioButtonStateChange } from '../common.js';
import type { SbbRadioButtonPanelElement } from '../radio-button-panel.js';
import type { SbbRadioButtonElement } from '../radio-button.js';
Expand Down Expand Up @@ -150,7 +149,7 @@ export class SbbRadioButtonGroupElement extends SbbDisabledMixin(LitElement) {
this._hasPanelElement = !!this.querySelector?.(
'sbb-selection-expansion-panel, sbb-radio-button-panel',
);
this.toggleAttribute('data-has-selection-expansion-panel', this._hasPanelElement);
this.toggleAttribute('data-has-panel', this._hasPanelElement);
this._updateRadios(this.value);
}

Expand Down Expand Up @@ -239,11 +238,8 @@ export class SbbRadioButtonGroupElement extends SbbDisabledMixin(LitElement) {

private _getRadioTabIndex(radio: SbbRadioButtonElement | SbbRadioButtonPanelElement): number {
const isSelected: boolean = radio.checked && !radio.disabled && !this.disabled;
const isParentPanelWithContent: boolean =
radio.parentElement?.localName === 'sbb-selection-expansion-panel' &&
(radio.parentElement as SbbSelectionExpansionPanelElement).hasContent;

return isSelected || (this._hasPanelElement && isParentPanelWithContent) ? 0 : -1;
return isSelected || this._hasPanelElement ? 0 : -1;
}

private _handleKeyDown(evt: KeyboardEvent): void {
Expand All @@ -269,11 +265,7 @@ export class SbbRadioButtonGroupElement extends SbbDisabledMixin(LitElement) {
);
const nextIndex: number = getNextElementIndex(evt, current, enabledRadios.length);

// Selection on arrow keypress is allowed only if all the selection-panels have no content.
const allPanelsHaveNoContent: boolean = (
Array.from(this.querySelectorAll?.('sbb-selection-expansion-panel')) || []
).every((e: SbbSelectionExpansionPanelElement) => !e.hasContent);
if (!this._hasPanelElement || (this._hasPanelElement && allPanelsHaveNoContent)) {
if (!this._hasPanelElement) {
enabledRadios[nextIndex].select();
}

Expand Down
6 changes: 5 additions & 1 deletion src/elements/radio-button/radio-button-panel/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ The `sbb-radio-button-panel` component provides the same functionality as a nati

## Slots

It is possible to provide a label via an unnamed slot; additionally the slote named `subtext` can be used to provide a subtext and the slot named `suffix` can be used to provide suffix items.
It is possible to provide a label via an unnamed slot;
additionally the slots named `subtext` can be used to provide a subtext and
the slot named `suffix` can be used to provide suffix items.
If you use a <sbb-card-badge>, the slot `badge` is automatically assigned.

```html
<sbb-radio-button-panel>
<sbb-card-badge>%</sbb-card-badge>
Label
<span slot="subtext">Subtext</span>
<span slot="suffix">Suffix</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@ snapshots["sbb-selection-expansion-panel renders DOM"] =
role="text"
slot="badge"
>
<span>
%
</span>
<span>
from CHF
</span>
<span>
19.99
</span>
%
</sbb-card-badge>
</sbb-checkbox-panel>
<div slot="content">
Expand Down Expand Up @@ -76,7 +68,7 @@ snapshots["sbb-selection-expansion-panel renders A11y tree Chrome"] =
"children": [
{
"role": "checkbox",
"name": "% from CHF 19.99 ​ Value one Suffix Subtext , collapsed",
"name": "% ​ Value one Suffix Subtext , collapsed",
"checked": false
}
]
Expand All @@ -93,7 +85,7 @@ snapshots["sbb-selection-expansion-panel renders A11y tree Firefox"] =
"children": [
{
"role": "checkbox",
"name": "% from CHF 19.99 ​ Value one Suffix Subtext , collapsed"
"name": "% ​ Value one Suffix Subtext , collapsed"
}
]
}
Expand Down
14 changes: 3 additions & 11 deletions src/elements/selection-expansion-panel/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The `sbb-selection-expansion-panel` component wraps either a [sbb-checkbox-panel](/docs/elements-sbb-checkbox-sbb-checkbox-panel--docs)
or a [sbb-radio-button-panel](/docs/elements-sbb-radio-button-sbb-radio-button-panel--docs) that can optionally toggle a content section.
or a [sbb-radio-button-panel](/docs/elements-sbb-radio-button-sbb-radio-button-panel--docs) that can toggle a content section.

The content section can be opened by checking `sbb-checkbox-panel` or selecting the `sbb-radio-button-panel`.
Additionally, clicking on all the upper area sets the checked state and therefore opens the content;
Expand All @@ -13,12 +13,8 @@ or a [sbb-checkbox-group](/docs/elements-sbb-checkbox-sbb-checkbox-group--docs).
```html
<sbb-radio-button-group>
<sbb-selection-expansion-panel>
<sbb-card-badge>
<span>%</span>
<span>from CHF</span>
<span>19.99</span>
</sbb-card-badge>
<sbb-radio-button-panel>
<sbb-card-badge>%</sbb-card-badge>
Value
<span slot="subtext">Subtext</span>
<span slot="suffix">
Expand All @@ -37,12 +33,8 @@ or a [sbb-checkbox-group](/docs/elements-sbb-checkbox-sbb-checkbox-group--docs).
```html
<sbb-checkbox-group>
<sbb-selection-expansion-panel>
<sbb-card-badge>
<span>%</span>
<span>from CHF</span>
<span>19.99</span>
</sbb-card-badge>
<sbb-checkbox-panel>
<sbb-card-badge>%</sbb-card-badge>
Value
<span slot="subtext">Subtext</span>
<span slot="suffix">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@ describe(`sbb-selection-expansion-panel`, () => {

describe('renders', () => {
beforeEach(async () => {
// Note: for easier testing, we add the slot="badge"
// to <sbb-card-badge> which would not be needed in real.
element = await fixture(html`
<sbb-selection-expansion-panel>
<sbb-checkbox-panel>
Value one
<span slot="subtext">Subtext</span>
<span slot="suffix">Suffix</span>
<sbb-card-badge slot="badge">
<span>%</span>
<span>from CHF</span>
<span>19.99</span>
</sbb-card-badge>
<sbb-card-badge>%</sbb-card-badge>
</sbb-checkbox-panel>
<div slot="content">Inner content</div>
</sbb-selection-expansion-panel>
Expand Down
Loading

0 comments on commit 2fc01d0

Please sign in to comment.