diff --git a/index.html b/index.html index 17d4e542..52a2a12c 100644 --- a/index.html +++ b/index.html @@ -669,9 +669,14 @@

Button

Checkbox

- 1 - 2 - 3 + Lorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fug + 2 + 3 test Submit
@@ -687,9 +692,13 @@

Radiogroup

Select an option - Option 1 - Option 2 - Option 3 + Lorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + soluta eaque fugit fuga distinctio? EumLorem ipsum dolor sit amet consectetur adipisicing elit. Maiores + Option 2 + Option 3 Submit
diff --git a/src/base/form-check-element.ts b/src/base/form-check-element.ts index 421476ea..6e521acc 100644 --- a/src/base/form-check-element.ts +++ b/src/base/form-check-element.ts @@ -134,12 +134,14 @@ export class FormCheckElement extends SgdsElement implements SgdsFormControl { @keydown=${this._handleKeyDown} @invalid=${(e: Event) => this._handleInvalid(e)} /> - - ${this.hasFeedback - ? html`
${this.invalidFeedback}
` - : nothing} +
+ + ${this.hasFeedback && this.invalid + ? html`
${this.invalidFeedback}
` + : nothing} +
`; } diff --git a/src/components/Checkbox/checkbox.css b/src/components/Checkbox/checkbox.css index 9df5eff8..6f998f33 100644 --- a/src/components/Checkbox/checkbox.css +++ b/src/components/Checkbox/checkbox.css @@ -16,7 +16,7 @@ input { } .form-check { - display: block; + display: flex; margin-bottom: var(--sgds-spacer-2); min-height: 2rem; } @@ -24,7 +24,6 @@ input { .form-check .form-check-input { margin-right: var(--sgds-form-input-margin-right); } - .form-check-input { appearance: none; background-color: var(--sgds-form-bg); @@ -69,11 +68,11 @@ input { .form-check-input.is-invalid:focus { box-shadow: var(--sgds-form-focus-invalid-box-shadow); } -.form-check-input.is-invalid ~ .form-check-label { +.form-check-input.is-invalid ~ .form-check-label-container > .form-check-label { color: var(--sgds-form-invalid-color); } .form-check-inline { - display: inline-block; + display: inline-flex; vertical-align: text-top; margin-right: var(--sgds-form-inline-margin-right); margin-bottom: 0; diff --git a/src/components/Input/sgds-input.ts b/src/components/Input/sgds-input.ts index 328fb326..4f4f8315 100644 --- a/src/components/Input/sgds-input.ts +++ b/src/components/Input/sgds-input.ts @@ -181,7 +181,7 @@ export class SgdsInput extends SgdsElement implements SgdsFormControl { ${this._renderFeedback()} `; } protected _renderFeedback() { - return this.hasFeedback + return this.hasFeedback && this.invalid ? html`
${this.invalidFeedback}
` : ""; } diff --git a/src/components/Radio/radio.css b/src/components/Radio/radio.css index 9474bc64..a29aac76 100644 --- a/src/components/Radio/radio.css +++ b/src/components/Radio/radio.css @@ -15,7 +15,7 @@ input { } .form-check { - display: block; + display: flex; margin-bottom: var(--sgds-spacer-2); min-height: 2rem; } diff --git a/src/components/Radio/sgds-radio-group.ts b/src/components/Radio/sgds-radio-group.ts index 001f8f32..bba84212 100644 --- a/src/components/Radio/sgds-radio-group.ts +++ b/src/components/Radio/sgds-radio-group.ts @@ -227,7 +227,7 @@ export class SgdsRadioGroup extends SgdsElement { tabindex="-1" @invalid=${(e: Event) => this._handleInvalid(e)} /> - ${this.hasFeedback ? html`
${this.invalidFeedback}
` : ""} + ${this.hasFeedback && this.invalid ? html`
${this.invalidFeedback}
` : ""} `; } diff --git a/src/components/Textarea/sgds-textarea.ts b/src/components/Textarea/sgds-textarea.ts index 9d041be4..a7e953b0 100644 --- a/src/components/Textarea/sgds-textarea.ts +++ b/src/components/Textarea/sgds-textarea.ts @@ -211,7 +211,7 @@ export class SgdsTextarea extends SgdsElement implements SgdsFormControl { > - ${this.hasFeedback + ${this.hasFeedback && this.invalid ? html`
${this.invalidFeedback}
` : ""} `; diff --git a/src/styles/feedback.css b/src/styles/feedback.css index 5b522200..bce4130a 100644 --- a/src/styles/feedback.css +++ b/src/styles/feedback.css @@ -1,10 +1,5 @@ .invalid-feedback { color: var(--sgds-form-invalid-color); - display: none; font-size: var(--sgds-form-feedback-font-size); width: 100%; } -.is-invalid ~ .invalid-feedback, -.was-validated :invalid ~ .invalid-feedback { - display: block; -} diff --git a/stories/templates/Checkbox/basic.js b/stories/templates/Checkbox/basic.js index 42049306..53a99065 100644 --- a/stories/templates/Checkbox/basic.js +++ b/stories/templates/Checkbox/basic.js @@ -16,6 +16,10 @@ export const Template = args => { ?isInline=${args.isInline} >Check me + Lorem ipsum dolor sit amet. Et itaque natus sit laborum voluptatem aut rerum ducimus eum tenetur molestias quo + reiciendis ratione aut eaque voluptates est `; }; export const args = { diff --git a/test/checkbox.test.ts b/test/checkbox.test.ts index 16fe238d..cc45e187 100644 --- a/test/checkbox.test.ts +++ b/test/checkbox.test.ts @@ -20,7 +20,7 @@ describe("", () => { }); it("id attribute should contain in .invalid-feedback id attribute", async () => { - const el = await fixture(html``); + const el = await fixture(html``); const input = el.shadowRoot?.querySelector("input"); const feedback = el.shadowRoot?.querySelector(".invalid-feedback"); expect(feedback?.getAttribute("id")).to.contain(input?.getAttribute("id")); @@ -59,7 +59,7 @@ describe("", () => { }); it("if class input is .is-invalid, feedback el should contain .invalid-feedback", async () => { - const el = await fixture(html``); + const el = await fixture(html``); const checkbox = el.shadowRoot?.querySelector("div.invalid-feedback"); expect(checkbox?.textContent).to.equal("test"); }); diff --git a/test/input.element.test.ts b/test/input.element.test.ts index 442c2254..f0b8c38f 100644 --- a/test/input.element.test.ts +++ b/test/input.element.test.ts @@ -33,13 +33,13 @@ describe("sgds-input", () => { const input = el.shadowRoot?.querySelector("input"); const label = el.shadowRoot?.querySelector("label"); const small = el.shadowRoot?.querySelector("small"); - const feedback = el.shadowRoot?.querySelector(".invalid-feedback"); + expect(input?.getAttribute("aria-labelledby")).not.to.contain("-invalid"); expect(input?.getAttribute("aria-labelledby")).to.contain(label?.getAttribute("id")); expect(input?.getAttribute("aria-labelledby")).to.contain(small?.getAttribute("id")); - expect(input?.getAttribute("aria-labelledby")).not.to.contain(feedback?.getAttribute("id")); el.invalid = true; await elementUpdated(el); + const feedback = el.shadowRoot?.querySelector(".invalid-feedback"); expect(input?.getAttribute("aria-labelledby")).to.contain(feedback?.getAttribute("id")); }); @@ -127,7 +127,7 @@ describe("sgds-input", () => { describe("Feedback UI optional", () => { it("when hasFeedback is true, div.invalid-feedback appears in shadowDOM", async () => { const el = await fixture( - html` ` + html` ` ); expect(el.shadowRoot?.querySelector("div.invalid-feedback")).not.to.be.null; expect(el.shadowRoot?.querySelector("div.invalid-feedback")?.textContent).to.equal("invalid feedback"); diff --git a/test/radio.test.ts b/test/radio.test.ts index 67bf6152..46305657 100644 --- a/test/radio.test.ts +++ b/test/radio.test.ts @@ -136,13 +136,15 @@ describe("", () => { ` ); + el.invalid = true; + await el.updateComplete; const invalidFeedback = el.shadowRoot?.querySelector("div.invalid-feedback"); expect(invalidFeedback?.textContent).to.equal(""); }); it("invalidFeedback sets the feedback message", async () => { const el = await fixture( html` - + two ` diff --git a/test/textarea.test.ts b/test/textarea.test.ts index 2e8486e9..d832f451 100644 --- a/test/textarea.test.ts +++ b/test/textarea.test.ts @@ -32,7 +32,7 @@ describe("sgds-textarea", () => { expect(label?.getAttribute("for")).to.equal(textarea?.getAttribute("id")); }); it("when invalid feedback element is in shadowm dom, its div id should contain same id value as textarea", async () => { - const el = await fixture(html` `); + const el = await fixture(html` `); const feedback = el.shadowRoot?.querySelector("div.invalid-feedback"); const textarea = el.shadowRoot?.querySelector("textarea"); expect(feedback?.getAttribute("id")).to.contain(textarea?.getAttribute("id")); @@ -56,12 +56,12 @@ describe("sgds-textarea", () => { expect(submitHandler).to.have.been.calledOnce; }); it("when hasFeedback is true, div.invalid-feedback appears", async () => { - const el = await fixture(html` `); + const el = await fixture(html` `); expect(el.shadowRoot?.querySelector("div.invalid-feedback")).to.exist; }); it("when hasFeedback is true, div.invalid-feedback appears and invalidFeedback value is forwarded to it", async () => { const el = await fixture(html` - + `); expect(el.shadowRoot?.querySelector("div.invalid-feedback")).to.exist; expect(el.shadowRoot?.querySelector("div.invalid-feedback")?.textContent).to.equal("teast"); @@ -157,7 +157,7 @@ describe("when maxlength is declared", () => { describe("Feedback UI optional", () => { it("when hasFeedback is true, div.invalid-feedback appears in shadowDOM", async () => { const el = await fixture( - html` ` + html` ` ); expect(el.shadowRoot?.querySelector("div.invalid-feedback")).not.to.be.null; expect(el.shadowRoot?.querySelector("div.invalid-feedback")?.textContent).to.equal("invalid feedback");