Skip to content

Commit 93adc81

Browse files
loivseniOvergaard
andauthored
feat: add missing native attributes to uui-input and uui-textarea (#484)
* pattern and other native attributes * escape dot on email regex (storybook) --------- Co-authored-by: Jacob Overgaard <[email protected]>
1 parent ec5cd77 commit 93adc81

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,25 @@ export class UUIInputElement extends FormControlMixin(
262262
this._type = value;
263263
}
264264

265+
/**
266+
* Validates the input based on the Regex pattern
267+
* @type {string}
268+
* @attr
269+
* @default undefined
270+
*/
271+
@property({ type: String })
272+
pattern?: string;
273+
274+
/**
275+
* The inputmode global attribute is an enumerated attribute that hints at the type of data that might be entered by the user while editing the element or its contents. This allows a browser to display an appropriate virtual keyboard.
276+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/inputmode|MDN} for further information
277+
* @type {string}
278+
* @attr
279+
* @default undefined
280+
*/
281+
@property({ type: String })
282+
inputmode?: string;
283+
265284
@query('#input')
266285
_input!: HTMLInputElement;
267286

@@ -357,9 +376,11 @@ export class UUIInputElement extends FormControlMixin(
357376
.type=${this.type}
358377
.value=${this.value as string}
359378
.name=${this.name}
379+
pattern=${ifDefined(this.pattern)}
360380
min=${ifDefined(this.min)}
361381
max=${ifDefined(this.max)}
362382
step=${ifDefined(this.step)}
383+
spellcheck=${ifDefined(this.spellcheck)}
363384
autocomplete=${ifDefined(this.autocomplete as any)}
364385
placeholder=${this.placeholder}
365386
aria-label=${this.label}

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ const Template: Story = props =>
4848
.type=${props.type}
4949
.name=${props.name}
5050
.placeholder=${props.placeholder}
51-
.value=${props.value}></uui-input>
51+
.value=${props.value}
52+
.spellcheck=${props.spellcheck}
53+
.autocomplete=${props.autocomplete}
54+
.pattern=${props.pattern}
55+
.errorMessage=${props.errorMessage}
56+
.inputmode=${props.inputmode}
57+
.minlength=${props.minlength}
58+
.maxlength=${props.maxlength}
59+
.minlength-message=${props.minlengthMessage}
60+
.maxlength-message=${props.maxlengthMessage}></uui-input>
5261
`;
5362

5463
export const AAAOverview = Template.bind({});
@@ -64,6 +73,39 @@ AAAOverview.parameters = {
6473
},
6574
};
6675

76+
export const PatternAndInputmode: Story = props =>
77+
html`Enter Email<br />
78+
<uui-input
79+
label="Email"
80+
error-message=${props.errorMessage}
81+
inputmode=${props.inputmode}
82+
pattern=${props.pattern}></uui-input>`;
83+
84+
PatternAndInputmode.args = {
85+
pattern: '[a-zA-Z0-9_.+\\-]+@[a-zA-Z0-9\\-]+\\.[a-zA-Z0-9\\-.]+',
86+
inputmode: 'email',
87+
errorMessage: 'Not an email',
88+
};
89+
90+
export const MinMaxLength = Template.bind({});
91+
MinMaxLength.args = {
92+
minlength: 3,
93+
maxlength: 4,
94+
minlengthMessage: 'Minimum 3',
95+
maxlengthMessage: 'Maximum 4',
96+
};
97+
MinMaxLength.parameters = {
98+
docs: {
99+
source: {
100+
code: html`<uui-input
101+
minlength="3"
102+
maxlength="4"
103+
minlength-message="Minimum 3"
104+
maxlength-message="Maximum 4"></uui-input>`.strings,
105+
},
106+
},
107+
};
108+
67109
export const NumberInput = Template.bind({});
68110
NumberInput.args = {
69111
placeholder: 'Input number',

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
33
import { property, query } from 'lit/decorators.js';
44
import { UUITextareaEvent } from './UUITextareaEvent';
55
import { FormControlMixin } from '@umbraco-ui/uui-base/lib/mixins';
6+
import { ifDefined } from 'lit/directives/if-defined.js';
67

78
/**
89
* @element uui-textarea
@@ -209,6 +210,31 @@ export class UUITextareaElement extends FormControlMixin(LitElement) {
209210
@property({ type: String })
210211
public label!: string;
211212

213+
/**
214+
* Sets the number of rows of the textarea
215+
* @type {number}
216+
* @attr
217+
*/
218+
@property({ type: Number })
219+
rows?: number;
220+
221+
/**
222+
* Sets the number of cols of the textarea
223+
* @type {number}
224+
* @attr
225+
*/
226+
@property({ type: Number })
227+
cols?: number;
228+
229+
/**
230+
* Indicates how the control should wrap the value for form submission. If this attribute is not specified, soft is its default value.
231+
* @type {'soft' | 'hard' | 'off'}
232+
* @attr
233+
* @default undefined
234+
*/
235+
@property({ type: String })
236+
wrap?: 'soft' | 'hard' | 'off';
237+
212238
constructor() {
213239
super();
214240

@@ -293,8 +319,11 @@ export class UUITextareaElement extends FormControlMixin(LitElement) {
293319
return html`
294320
<textarea
295321
id="textarea"
322+
.rows=${this.rows}
323+
.cols=${this.cols}
296324
.value=${this.value as string}
297325
.name=${this.name}
326+
wrap=${ifDefined(this.wrap)}
298327
placeholder=${this.placeholder}
299328
aria-label=${this.label}
300329
.disabled=${this.disabled}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export default {
1313
value: '',
1414
label: 'Label',
1515
placeholder: 'Placeholder',
16+
rows: '',
17+
cols: '',
18+
wrap: '',
1619
},
1720
};
1821

@@ -39,6 +42,9 @@ export const AAAOverview: Story = props => {
3942
.placeholder=${props.placeholder}
4043
?disabled=${props.disabled}
4144
?readonly=${props.readonly}
45+
.rows=${props.rows}
46+
.cols="${props.cols}"
47+
.wrap=${props.wrap}
4248
.name=${props.name}
4349
.error=${props.error}
4450
.value=${props.value}></uui-textarea>`;

0 commit comments

Comments
 (0)