`;
-/* end snapshot sbb-form-field should render select without label */
+/* end snapshot sbb-form-field should render select without label Shadow DOM */
+
+snapshots["sbb-form-field renders select with optional flag and borderless DOM"] =
+`
+`;
+/* end snapshot sbb-form-field renders select with optional flag and borderless DOM */
-snapshots["sbb-form-field renders select with optional flag and borderless"] =
+snapshots["sbb-form-field renders select with optional flag and borderless Shadow DOM"] =
`
`;
-/* end snapshot sbb-form-field renders select with optional flag and borderless */
+/* end snapshot sbb-form-field renders select with optional flag and borderless Shadow DOM */
snapshots["sbb-form-field A11y tree Chrome"] =
`
diff --git a/src/components/form-field/form-field/form-field.e2e.ts b/src/components/form-field/form-field/form-field.e2e.ts
index 1513c0fd63..018c6ee65a 100644
--- a/src/components/form-field/form-field/form-field.e2e.ts
+++ b/src/components/form-field/form-field/form-field.e2e.ts
@@ -25,18 +25,6 @@ describe(`sbb-form-field with ${fixture.name}`, () => {
assert.instanceOf(element, SbbFormFieldElement);
});
- it('should remove the label element if no label is configured', async () => {
- expect(element.querySelector('label')).to.be.null;
-
- element.setAttribute('label', 'Label');
- await waitForLitRender(element);
- expect(element.querySelector('label')).not.to.be.null;
-
- element.removeAttribute('label');
- await waitForLitRender(element);
- expect(element.querySelector('label')).to.be.null;
- });
-
it('should update empty input state', async () => {
expect(element).to.have.attribute('data-input-empty');
@@ -85,11 +73,12 @@ describe(`sbb-form-field with ${fixture.name}`, () => {
});
it('should assign id to input and reference it in the label', async () => {
- element.setAttribute('label', 'Example');
- await waitForLitRender(element);
- const label = element.querySelector('label');
+ const newLabel = document.createElement('label');
+ newLabel.textContent = 'Example';
+ element.prepend(newLabel);
await waitForLitRender(element);
+ const label = element.querySelector('label');
expect(input.id).to.match(/^sbb-form-field-input-/);
expect(label).to.have.attribute('for', input.id);
@@ -147,7 +136,8 @@ describe(`sbb-form-field with ${fixture.name}`, () => {
beforeEach(async () => {
element = await fixture(
html`
-
+
+
Test
`,
@@ -198,8 +188,6 @@ describe(`sbb-form-field with ${fixture.name}`, () => {
});
it('should assign id to label and reference it in the sbb-select', async () => {
- element.setAttribute('label', 'Example');
- await waitForLitRender(element);
const label = element.querySelector('label')!;
expect(label.id).to.match(/^sbb-form-field-label-/);
diff --git a/src/components/form-field/form-field/form-field.spec.ts b/src/components/form-field/form-field/form-field.spec.ts
index 10525e85a6..e4ad14bb25 100644
--- a/src/components/form-field/form-field/form-field.spec.ts
+++ b/src/components/form-field/form-field/form-field.spec.ts
@@ -5,155 +5,119 @@ import { fixture, testA11yTreeSnapshot } from '../../core/testing/private';
import './form-field';
import '../../form-error';
+import type { SbbFormFieldElement } from './form-field';
describe(`sbb-form-field`, () => {
- it('renders input', async () => {
- const root = await fixture(
- html`
-
- `,
- );
-
- expect(root).dom.to.be.equal(`
-
-
-
-
- `);
- await expect(root).shadowDom.to.be.equalSnapshot();
+ describe('renders input', () => {
+ let element: SbbFormFieldElement;
+
+ beforeEach(async () => {
+ element = await fixture(
+ html`
+
+
+ `,
+ );
+ });
+
+ it('DOM', async () => {
+ await expect(element).dom.to.be.equalSnapshot();
+ });
+
+ it('Shadow DOM', async () => {
+ await expect(element).shadowDom.to.be.equalSnapshot();
+ });
});
- it('renders slotted label', async () => {
- const root = await fixture(html`
-
-
-
-
- `);
-
- expect(root).dom.to.be.equal(`
-
-
-
-
- `);
-
- await expect(root).shadowDom.to.be.equalSnapshot();
+ describe('renders disabled input', () => {
+ let element: SbbFormFieldElement;
+
+ beforeEach(async () => {
+ element = await fixture(html`
+
+
+
+
+ `);
+ });
+
+ it('DOM', async () => {
+ await expect(element).dom.to.be.equalSnapshot();
+ });
+
+ it('Shadow DOM', async () => {
+ await expect(element).shadowDom.to.be.equalSnapshot();
+ });
});
- it('renders disabled input', async () => {
- const root = await fixture(html`
-
-
-
- `);
-
- expect(root).dom.to.be.equal(`
-
-
-
-
- `);
- await expect(root).shadowDom.to.be.equalSnapshot();
+ describe('renders readonly input with error', () => {
+ let element: SbbFormFieldElement;
+
+ beforeEach(async () => {
+ element = await fixture(html`
+
+
+
+ You can't change this value.
+
+ `);
+ });
+
+ it('DOM', async () => {
+ await expect(element).dom.to.be.equalSnapshot();
+ });
+
+ it('Shadow DOM', async () => {
+ await expect(element).shadowDom.to.be.equalSnapshot();
+ });
});
- it('renders readonly input with error', async () => {
- const root = await fixture(html`
-
-
- You can't change this value.
-
- `);
-
- expect(root).dom.to.be.equal(`
-
-
-
-
- You can't change this value.
-
-
- `);
- await expect(root).shadowDom.to.be.equalSnapshot();
+ describe('should render select without label', () => {
+ let element: SbbFormFieldElement;
+ beforeEach(async () => {
+ element = await fixture(html`
+
+
+
+ `);
+ });
+
+ it('DOM', async () => {
+ await expect(element).dom.to.be.equalSnapshot();
+ });
+
+ it('Shadow DOM', async () => {
+ await expect(element).shadowDom.to.be.equalSnapshot();
+ });
});
- it('should render select without label', async () => {
- const root = await fixture(html`
-
-
-
- `);
-
- expect(root).dom.to.be.equal(`
-
-
-
- `);
- await expect(root).shadowDom.to.be.equalSnapshot();
- });
-
- it('renders select with optional flag and borderless', async () => {
- const root = await fixture(html`
-
-
-
- `);
-
- expect(root).dom.to.be.equal(`
-
-
-
-
- `);
- await expect(root).shadowDom.to.be.equalSnapshot();
+ describe('renders select with optional flag and borderless', () => {
+ let element: SbbFormFieldElement;
+
+ beforeEach(async () => {
+ element = await fixture(html`
+
+
+
+
+ `);
+ });
+
+ it('DOM', async () => {
+ await expect(element).dom.to.be.equalSnapshot();
+ });
+
+ it('Shadow DOM', async () => {
+ await expect(element).shadowDom.to.be.equalSnapshot();
+ });
});
testA11yTreeSnapshot(html`
diff --git a/src/components/form-field/form-field/form-field.stories.ts b/src/components/form-field/form-field/form-field.stories.ts
index 02c371ccc1..466eb84ac5 100644
--- a/src/components/form-field/form-field/form-field.stories.ts
+++ b/src/components/form-field/form-field/form-field.stories.ts
@@ -77,7 +77,6 @@ const TemplateInput = ({
}: Args): TemplateResult => html`
- ${TemplateBasicInput(args)}
+ ${label ? html`` : nothing} ${TemplateBasicInput(args)}
`;
-const TemplateInputWithSlottedLabel = ({
+const TemplateInputWithSlottedSpanLabel = ({
'error-space': errorSpace,
label,
optional,
@@ -127,7 +126,6 @@ const TemplateInputWithErrorSpace = (args: Args): TemplateResult => {
{
?floating-label=${args['floating-label']}
?negative=${args.negative}
>
+ ${args.label ? html`` : nothing}
{
const input = event.currentTarget as HTMLInputElement;
@@ -162,20 +161,23 @@ const TemplateInputWithErrorSpace = (args: Args): TemplateResult => {
`;
};
-const TemplateInputWithIcons = (args: Args): TemplateResult => html`
+const TemplateInputWithIcons = ({ label, ...args }: Args): TemplateResult => html`
+ ${label ? html`` : nothing}
${TemplateBasicInput(args)} ${PopoverTrigger()}
`;
const TemplateInputWithMiniButton = ({
+ label,
disabled,
readonly,
active,
...args
}: Args): TemplateResult => html`
+ ${label ? html`` : nothing}
${TemplateBasicInput({ disabled, readonly, ...args })}
html`
+ ${label ? html`` : nothing}
${TemplateBasicInput({ disabled, readonly, ...args })}
@@ -202,7 +206,6 @@ const TemplateInputWithClearButton = ({
const TemplateSelect = (args: Args): TemplateResult => html`
html`
?floating-label=${args['floating-label']}
?negative=${args.negative}
>
- ${TemplateBasicSelect(args)}
+ ${args.label ? html`` : nothing} ${TemplateBasicSelect(args)}
`;
@@ -225,7 +228,6 @@ const TemplateSelectWithErrorSpace = (args: Args): TemplateResult => {
{
?floating-label=${args['floating-label']}
?negative=${args.negative}
>
+ ${args.label ? html`` : nothing}