Skip to content

Commit c8e8798

Browse files
loivseniOvergaard
andauthored
feat: adds min, max, and step property to the uui-input (#457)
Co-authored-by: Jacob Overgaard <[email protected]>
1 parent 8b8f8aa commit c8e8798

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
lines changed

packages/uui-input/lib/uui-input.element.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,17 @@ export class UUIInputElement extends FormControlMixin(
148148
];
149149

150150
/**
151-
* This is a minimum value of the input.
151+
* Sets the min value of the input.
152+
* Examples: the first date the user may pick in date and datetime-local, or the min numeric value the user can pick in a number input.
153+
* @type {number | string}
154+
* @attr
155+
* @default undefined
156+
*/
157+
@property()
158+
min?: number | string;
159+
160+
/**
161+
* Sets the minimum length of the value of the input.
152162
* @type {number}
153163
* @attr
154164
* @default undefined
@@ -166,7 +176,17 @@ export class UUIInputElement extends FormControlMixin(
166176
minlengthMessage = 'This field need more characters';
167177

168178
/**
169-
* This is a maximum value of the input.
179+
* Sets the max value of the input.
180+
* Examples: the last date the user may pick in date and datetime-local, or the max numeric value the user can pick in a number input.
181+
* @type {number | string}
182+
* @attr
183+
* @default undefined
184+
*/
185+
@property()
186+
max?: number | string;
187+
188+
/**
189+
* Sets the maximum length of the value of the input.
170190
* @type {number}
171191
* @attr
172192
* @default undefined
@@ -183,6 +203,15 @@ export class UUIInputElement extends FormControlMixin(
183203
@property({ type: String, attribute: 'maxlength-message' })
184204
maxlengthMessage = 'This field exceeds the allowed amount of characters';
185205

206+
/**
207+
* Specifies the interval between legal numbers of the input
208+
* @type {number}
209+
* @attr
210+
* @default undefined
211+
*/
212+
@property({ type: Number })
213+
step?: number;
214+
186215
/**
187216
* Disables the input.
188217
* @type {boolean}
@@ -328,6 +357,9 @@ export class UUIInputElement extends FormControlMixin(
328357
.type=${this.type}
329358
.value=${this.value as string}
330359
.name=${this.name}
360+
min=${ifDefined(this.min)}
361+
max=${ifDefined(this.max)}
362+
step=${ifDefined(this.step)}
331363
autocomplete=${ifDefined(this.autocomplete as any)}
332364
placeholder=${this.placeholder}
333365
aria-label=${this.label}

packages/uui-input/lib/uui-input.story.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default {
3838
const Template: Story = props =>
3939
html`
4040
<uui-input
41+
.min=${props.min}
42+
.max=${props.max}
43+
.step=${props.step}
4144
.disabled=${props.disabled}
4245
.readonly=${props.readonly}
4346
.error=${props.error}
@@ -61,6 +64,65 @@ AAAOverview.parameters = {
6164
},
6265
};
6366

67+
export const NumberInput = Template.bind({});
68+
NumberInput.args = {
69+
placeholder: 'Input number',
70+
type: 'number',
71+
step: 5,
72+
value: '10',
73+
min: -50,
74+
max: 50,
75+
};
76+
NumberInput.parameters = {
77+
controls: {
78+
include: [
79+
'type',
80+
'value',
81+
'label',
82+
'min',
83+
'max',
84+
'step',
85+
'disabled',
86+
'readonly',
87+
],
88+
},
89+
docs: {
90+
source: {
91+
code: html` <uui-input
92+
type="number"
93+
value="5"
94+
label="Label"
95+
min="-50"
96+
max="50"
97+
step="5">
98+
</uui-input>`.strings,
99+
},
100+
},
101+
};
102+
103+
export const DateTimeLocal = Template.bind({});
104+
DateTimeLocal.args = {
105+
type: 'datetime-local',
106+
value: '2023-04-20T10:00',
107+
min: '2023-04-13T10:00',
108+
max: '2023-04-28T16:00',
109+
};
110+
DateTimeLocal.parameters = {
111+
controls: {
112+
include: ['type', 'value', 'min', 'max', 'step', 'disabled', 'readonly'],
113+
},
114+
docs: {
115+
source: {
116+
code: html` <uui-input
117+
type="datetime-local"
118+
min="2023-04-13T10:00"
119+
value="2023-04-20T10:00"
120+
max="2023-04-28T16:00">
121+
</uui-input>`.strings,
122+
},
123+
},
124+
};
125+
64126
export const Label = Template.bind({});
65127
Label.args = { type: 'text' };
66128
Label.parameters = {
@@ -97,6 +159,9 @@ Error.parameters = {
97159
export const PrependAndAppend: Story = props =>
98160
html`
99161
<uui-input
162+
.min=${props.min}
163+
.max=${props.max}
164+
.step=${props.step}
100165
.disabled=${props.disabled}
101166
.readonly=${props.readonly}
102167
.error=${props.error}
@@ -140,6 +205,9 @@ export const PrependAndAppend: Story = props =>
140205

141206
export const PrependIcon: Story = props =>
142207
html` <uui-input
208+
.min=${props.min}
209+
.max=${props.max}
210+
.step=${props.step}
143211
.disabled=${props.disabled}
144212
.readonly=${props.readonly}
145213
.error=${props.error}
@@ -157,6 +225,9 @@ export const PrependIcon: Story = props =>
157225

158226
export const AppendIcon: Story = props =>
159227
html` <uui-input
228+
.min=${props.min}
229+
.max=${props.max}
230+
.step=${props.step}
160231
.disabled=${props.disabled}
161232
.readonly=${props.readonly}
162233
.error=${props.error}
@@ -177,6 +248,9 @@ export const AppendIcon: Story = props =>
177248
export const MultipleInputs: Story = props =>
178249
html`
179250
<uui-input
251+
.min=${props.min}
252+
.max=${props.max}
253+
.step=${props.step}
180254
.disabled=${props.disabled}
181255
.readonly=${props.readonly}
182256
.error=${props.error}

0 commit comments

Comments
 (0)