Skip to content

Commit c5e55b8

Browse files
ondrej-kasparadamkudrna
authored andcommitted
Feat(web): Add support for TextField's size attribute #DS-154
1 parent 663be5f commit c5e55b8

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

examples/web/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ <h2 class="typography-heading-medium-text mt-1100 mb-800">TextField</h2>
199199
<label for="textfieldEmail" class="TextField__label TextField__label--required">E-mail</label>
200200
<input type="email" id="textfieldEmail" class="TextField__input" />
201201
</div>
202+
<div class="TextField">
203+
<label for="textfieldNumber" class="TextField__label">Number (2 digits)</label>
204+
<input type="number" size="2" id="textfieldNumber" class="TextField__input" />
205+
</div>
202206
<div class="TextField">
203207
<label for="textfieldMessage" class="TextField__label">Label</label>
204208
<input type="text" id="textfieldMessage" class="TextField__input" placeholder="Placeholder" />

examples/web/jobs.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ <h2 class="jobs-typography-heading-medium-text jobs-mt-1100 jobs-mb-800">TextFie
206206
<label for="textfieldEmail" class="jobs-TextField__label jobs-TextField__label--required">E-mail</label>
207207
<input type="email" id="textfieldEmail" class="jobs-TextField__input" />
208208
</div>
209+
<div class="jobs-TextField">
210+
<label for="textfieldNumber" class="jobs-TextField__label">Number (2 digits)</label>
211+
<input type="number" size="2" id="textfieldNumber" class="jobs-TextField__input" />
212+
</div>
209213
<div class="jobs-TextField">
210214
<label for="textfieldMessage" class="jobs-TextField__label">Label</label>
211215
<input type="text" id="textfieldMessage" class="jobs-TextField__input" placeholder="Placeholder" />

packages/web/src/scss/components/TextField/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ TextField supports the following input types:
5353

5454
Other meaningful values (e.g. `date`, `file`) will work but design of the input field is not consistent across platforms/browsers.
5555

56+
## Input width
57+
58+
There are several ways to adjust the input width:
59+
60+
### `size` attribute
61+
62+
The `size` attribute is supported on inputs of the following types: `email`, `password`, `tel`, `text`, `url`.
63+
64+
This option is generally recommended for inputs with a limited value length (e.g. numeric representation of day, month, year). Supported values are `2`, `3` and `4` (characters). If you need any other value or prefer using `em` unit instead of default `ch`, define a `--width` CSS custom property on the `<input>` element:
65+
66+
```html
67+
<div class="TextField">
68+
<label for="textfield-size" class="TextField__label">4000 (in Roman numerals)</label>
69+
<input type="text" size="4" id="textfield-size" class="TextField__input" style="--width: 4em;" />
70+
</div>
71+
```
72+
73+
### Grid
74+
75+
For other use cases (wider input or input with unknown value length), we recommend placing them inside the Grid component and using `TextField--fluid` modifier to fill the available space.
76+
5677
## TextField password toggle
5778

5879
TextField with `type="password"` can have a toggle button. When toggling don't forget to change

packages/web/src/scss/components/TextField/_TextField.scss

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@
5353
&[type='url'] {
5454
appearance: none;
5555
}
56+
57+
&[type='number'] {
58+
--arrows-width: #{theme.$input-number-arrows-width};
59+
}
60+
61+
&[size] {
62+
width: calc(
63+
var(--width) + 2 * #{theme.$input-padding-x} + 2 * #{theme.$input-border-width} + var(--arrows-width, 0px)
64+
);
65+
}
66+
67+
@each $size in theme.$input-size-characters {
68+
&[size='#{$size}'] {
69+
--width: #{$size}ch;
70+
}
71+
}
5672
}
5773

5874
.TextField--fluid {

packages/web/src/scss/components/TextField/_theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ $input-background: tokens.$background-basic;
2727
$input-focus-shadow: tokens.$focus;
2828
$input-placeholder-color-default: tokens.$text-secondary-default;
2929
$input-placeholder-color-disabled: tokens.$text-secondary-disabled;
30+
$input-size-characters: (2, 3, 4);
31+
$input-number-arrows-width: 1.25rem;
3032

3133
$input-password-toggle-padding: tokens.$space-400;
3234
$input-password-toggle-icon-size: tokens.$space-700;

0 commit comments

Comments
 (0)