diff --git a/src/components/input/bl-input.css b/src/components/input/bl-input.css index 92a86824..c8d9a452 100644 --- a/src/components/input/bl-input.css +++ b/src/components/input/bl-input.css @@ -154,6 +154,14 @@ input:disabled { cursor: not-allowed; } +input::-webkit-calendar-picker-indicator { + display: none; +} + +input::-moz-calendar-picker-indicator { + display: none; +} + input:autofill { background-color: var(--autofill-bg-color); diff --git a/src/components/input/bl-input.stories.mdx b/src/components/input/bl-input.stories.mdx index 37ee6385..fca705a9 100644 --- a/src/components/input/bl-input.stories.mdx +++ b/src/components/input/bl-input.stories.mdx @@ -238,6 +238,24 @@ Input also supports slot icons for more complex use cases. You can use `icon` sl +Inputs with type of date, time, datetime-local, month, week and search have default icons. You can override these icons with `icon` attribute. + + + + {SingleInputTemplate.bind({})} + + + {SingleInputTemplate.bind({})} + + + {SingleInputTemplate.bind({})} + + + {SingleInputTemplate.bind({})} + + + + ## Input Validation Input supports native HTML validation rules like `required`, `minlength`, `maxlength`, `min` and `max`. Other validation rules will come soon. diff --git a/src/components/input/bl-input.test.ts b/src/components/input/bl-input.test.ts index ccdaee66..21bb3844 100644 --- a/src/components/input/bl-input.test.ts +++ b/src/components/input/bl-input.test.ts @@ -85,6 +85,25 @@ describe("bl-input", () => { }); describe("input with icon", () => { + it("should show default icon", async () => { + const el = await fixture(html``); + const defaultIcon = el.shadowRoot?.querySelector('bl-icon[name="clock"]'); + + expect(defaultIcon).to.exist; + expect(defaultIcon?.getAttribute("name")).to.equal("clock"); + expect(el.shadowRoot?.querySelector(".has-icon")).to.exist; + }); + + it("should override default icon when custom icon is set", async () => { + const el = await fixture(html``); + const defaultIcon = el.shadowRoot?.querySelector('bl-icon[name="clock"]'); + const customIcon = el.shadowRoot?.querySelector('bl-icon[name="academy"]'); + + expect(defaultIcon).to.not.exist; + expect(customIcon).to.exist; + expect(el.shadowRoot?.querySelector(".has-icon")).to.exist; + }); + it("should show custom icon", async () => { const el = await fixture(html``); const customIcon = el.shadowRoot?.querySelector('bl-icon[name="info"]'); diff --git a/src/components/input/bl-input.ts b/src/components/input/bl-input.ts index 93456162..2698d3c0 100644 --- a/src/components/input/bl-input.ts +++ b/src/components/input/bl-input.ts @@ -24,7 +24,17 @@ export type InputType = | "password" | "number" | "tel" - | "url"; + | "url" + | "search"; + +const inputTypeIcons: Partial> = { + "date": "calendar", + "datetime-local": "calendar", + "month": "calendar", + "week": "calendar", + "time": "clock", + "search": "search", +}; export type InputSize = "small" | "medium" | "large"; /** @@ -53,7 +63,7 @@ export default class BlInput extends FormControlMixin(LitElement) { name?: string; /** - * Type of the input. It's used to set `type` attribute of native input inside. Only `text`, `number` and `password` is supported for now. + * Type of the input. It's used to set `type` attribute of native input inside. */ @property({ reflect: true }) type: InputType = "text"; @@ -284,6 +294,7 @@ export default class BlInput extends FormControlMixin(LitElement) { firstUpdated() { this.setValue(this.value); + if (!this.icon) this.icon = inputTypeIcons[this.type]; } protected async updated(changedProperties: PropertyValues) {