From b614923e994ac406318caf7f6e129bb4a103c681 Mon Sep 17 00:00:00 2001
From: Davide Mininni
<101575400+DavideMininni-Fincons@users.noreply.github.com>
Date: Thu, 22 Aug 2024 15:51:04 +0200
Subject: [PATCH] feat(sbb-select): introduce size s (#3011)
---
.../form-field/form-field/form-field.scss | 9 +++-
src/elements/select/readme.md | 11 +++++
src/elements/select/select.stories.ts | 48 +++++++++++++++++++
src/elements/select/select.visual.spec.ts | 28 ++++++++++-
4 files changed, 94 insertions(+), 2 deletions(-)
diff --git a/src/elements/form-field/form-field/form-field.scss b/src/elements/form-field/form-field/form-field.scss
index f02608a5d1..62c6dd5f8b 100644
--- a/src/elements/form-field/form-field/form-field.scss
+++ b/src/elements/form-field/form-field/form-field.scss
@@ -388,7 +388,14 @@
.sbb-form-field__input {
display: flex;
- :host([size='s']:is([data-input-type='input'], [data-input-type='select'])) & {
+ :host(
+ [size='s']:is(
+ [data-input-type='input'],
+ [data-input-type='select'],
+ [data-input-type='sbb-select']
+ )
+ )
+ & {
// In size s, the natural height of the text input is too small.
// To not reserve too much space, we decrease the height.
margin-block-end: #{sbb.px-to-rem-build(-2)};
diff --git a/src/elements/select/readme.md b/src/elements/select/readme.md
index 0f1354c9e6..39c418ec57 100644
--- a/src/elements/select/readme.md
+++ b/src/elements/select/readme.md
@@ -70,6 +70,17 @@ the selected values will be displayed in selection order, separated by a comma.
```
+## Style
+
+The component has no `size` property but, when slotted in a `sbb-form-field`, it adapts to the parent `size`.
+
+```html
+
+
+ ...
+
+```
+
## Events
Consumers can listen to the native `change`/`input` event on the `sbb-select` component to intercept the selection's change;
diff --git a/src/elements/select/select.stories.ts b/src/elements/select/select.stories.ts
index ff6dca943d..1843f7bcc8 100644
--- a/src/elements/select/select.stories.ts
+++ b/src/elements/select/select.stories.ts
@@ -49,6 +49,16 @@ const borderless: InputType = {
},
};
+const size: InputType = {
+ control: {
+ type: 'inline-radio',
+ },
+ options: ['m', 's'],
+ table: {
+ category: 'Form field',
+ },
+};
+
const negative: InputType = {
control: {
type: 'boolean',
@@ -160,6 +170,7 @@ const disableGroup: InputType = {
const defaultArgTypes: ArgTypes = {
borderless,
+ size,
negative,
floatingLabel,
value,
@@ -176,6 +187,7 @@ const defaultArgTypes: ArgTypes = {
const defaultArgs: Args = {
borderless: false,
+ size: size.options![0],
negative: false,
floatingLabel: false,
value: undefined,
@@ -280,6 +292,7 @@ const createOptionsGroup = (
const FormFieldTemplate = ({
borderless,
+ size,
negative,
floatingLabel,
numberOfOptions,
@@ -291,6 +304,7 @@ const FormFieldTemplate = ({
html`
{
const valueEllipsis: string = 'This label name is so long that it needs ellipsis to fit.';
const defaultArgs = {
borderless: false,
+ size: 'm',
negative: false,
disableOption: false,
withOptionGroup: false,
@@ -53,6 +54,7 @@ describe('sbb-select', () => {
const template = ({
borderless,
+ size,
negative,
disableOption,
withOptionGroup,
@@ -64,7 +66,7 @@ describe('sbb-select', () => {
args.value = [args.value as string];
}
return html`
-
+
{
}),
);
+ for (const value of [undefined, 'Option 1']) {
+ it(
+ `negative=${negative} multiple=${multiple} value=${value} size=s`,
+ visualDiffDefault.with(async (setup) => {
+ await setup.withFixture(
+ template({
+ ...defaultArgs,
+ negative,
+ multiple,
+ size: 's',
+ value,
+ }),
+ {
+ minHeight: '600px',
+ backgroundColor: negative ? 'var(--sbb-color-black)' : undefined,
+ },
+ );
+ setup.withPostSetupAction(() => {
+ const select = setup.snapshotElement.querySelector('sbb-select')!;
+ select.open();
+ });
+ }),
+ );
+ }
it(
`negative=${negative} multiple=${multiple} disableOption=true`,
visualDiffDefault.with(async (setup) => {