Skip to content

Commit 4977dbe

Browse files
authored
fix: improve text inputs (#168)
* fix: add type of the text-field component * feat: add min and max properties to text-field component * feat: add minLength and maxLenght properties to text-field component * feat: add pattern property to text-field component * feat: add step property to text-field component * feat: add types for inputmode property to text-field component * style: clean types * style: clean types * fix: simplify the textfield props
1 parent 14d86c8 commit 4977dbe

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

src/text-field/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,23 @@ import { inputStyles } from '../input';
1313
* @prop {string} [label=''] - The label for the text field.
1414
* @prop {string} [name=''] - The name of the text field.
1515
* @prop {string} [placeholder=''] - The placeholder text for the text field.
16-
* @prop {string} [inputmode=''] - The input mode for the text field.
17-
* @prop {string} [type=''] - The type of the text field.
16+
* @prop {'none'|'text'|'tel'|'url'|'email'|'numeric'|'decimal'|'search'} [inputmode] - The input mode for the text field.
17+
* @prop {'text'|'date'|'month'|'time'|'week'|'datetime-local'|'number'|'password'|'search'|'tel'|'url'|'email'} [type='text'] - The type of the text field.
1818
* @prop {string} [autocomplete=''] - The autocomplete attribute for the text field.
19+
* @prop {number} [max] - The maximum value of the text field; only applying to text fields with these types: `date`, `month`, `week`, `time`, `datetime-local`, `number`.
20+
* @prop {number} [min] - The minimum value of the text field; only applying to text fields with these types: `date`, `month`, `week`, `time`, `datetime-local`, `number`.
21+
* @prop {number} [maxLength] - The maximum length of the text field; only applying to text fields with these types: `text`, `search`, `url`, `tel`, `email`, `password`.
22+
* @prop {number} [minLength] - The minimum length of the text field; only applying to text fields with these types: `text`, `search`, `url`, `tel`, `email`, `password`.
23+
* @prop {string} [pattern] - The allowed regex pattern of the text field; only applying to text fields with these types: `text`, `search`, `url`, `tel`, `email`, `password`.
24+
* @prop {number} [step] - The step of the text field; only applying to text fields with these types: `date`, `month`, `week`, `time`, `datetime-local`, `number`.
1925
*
2026
* @csspart [field] - The main container for the text field.
2127
* @csspart [label] - The label for the text field.
2228
* @csspart [container] - The container for the input and any leading/trailing elements.
2329
* @csspart [input] - The input element.
2430
* @csspart [caption] - The caption for the text field.
31+
* @csspart [leading] - The leading for the text field.
32+
* @csspart [trailing] - The trailing for the text field.
2533
*
2634
* @slot [leading] - the leading slot of the text-field
2735
* @slot [trailing] - the trailing slot of the text-field

src/text-field/text-field.style.ts

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export default css`
2525
font-family: inherit;
2626
}
2727
28+
.input::-webkit-calendar-picker-indicator {
29+
filter: brightness(0);
30+
}
31+
2832
.input::placeholder {
2933
color: var(
3034
--tap-text-field-input-placeholder-color,

src/text-field/text-field.ts

+42-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
1-
import { TemplateResult, html } from 'lit';
1+
import { TemplateResult, html, nothing } from 'lit';
22
import { property } from 'lit/decorators.js';
33
import { ifDefined } from 'lit/directives/if-defined.js';
44
import { live } from 'lit/directives/live.js';
55
import { Input } from '../input';
66

77
export class TextField extends Input {
8-
@property({ type: String }) inputmode?: string; // TODO: add type
8+
@property({ type: String }) inputmode?:
9+
| 'none'
10+
| 'text'
11+
| 'tel'
12+
| 'url'
13+
| 'email'
14+
| 'numeric'
15+
| 'decimal'
16+
| 'search';
917

10-
@property({ type: String }) type?: string; // TODO: add type
18+
@property({ type: String }) type:
19+
| 'text'
20+
| 'date'
21+
| 'month'
22+
| 'time'
23+
| 'week'
24+
| 'datetime-local'
25+
| 'number'
26+
| 'password'
27+
| 'search'
28+
| 'tel'
29+
| 'url'
30+
| 'email' = 'text';
31+
32+
@property({ type: Number }) max?: number;
33+
@property({ type: Number }) min?: number;
34+
35+
@property({ type: Number }) maxLength?: number;
36+
@property({ type: Number }) minLength?: number;
37+
38+
@property({ type: String }) pattern?: string;
39+
40+
@property({ type: Number }) step?: number;
1141

1242
@property({ type: String }) autocomplete?: string; // TODO: add type
1343

1444
// TODO: check if using generic ids for caption and input is ok
1545
protected renderInput(): TemplateResult {
1646
return html`
17-
<slot name="leading"></slot>
47+
<slot part="leading" name="leading"></slot>
1848
<input
1949
id="input"
2050
class="input"
@@ -27,11 +57,17 @@ export class TextField extends Input {
2757
inputmode=${ifDefined(this.inputmode)}
2858
placeholder=${ifDefined(this.placeholder)}
2959
autocomplete=${ifDefined(this.autocomplete)}
30-
type=${ifDefined(this.type)}
60+
max=${ifDefined(this.min)}
61+
min=${ifDefined(this.max)}
62+
maxlength=${ifDefined(this.maxLength)}
63+
minlength=${ifDefined(this.minLength)}
64+
pattern=${ifDefined(this.pattern)}
65+
step=${ifDefined(this.step)}
66+
type=${this.type}
3167
.value=${live(this.value)}
3268
@input=${this.handleInput}
3369
/>
34-
<slot name="trailing"></slot>
70+
<slot part="trailing" name="trailing"></slot>
3571
`;
3672
}
3773
}

0 commit comments

Comments
 (0)