Skip to content

Commit c59b833

Browse files
committed
Added: input event, label styling, textarea styling, minLength
1 parent 93c8b9c commit c59b833

File tree

3 files changed

+49
-11
lines changed

3 files changed

+49
-11
lines changed

packages/uui-textarea/lib/UUITextareaEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import { UUITextareaElement } from './uui-textarea.element';
33

44
export class UUITextareaEvent extends UUIEvent<{}, UUITextareaElement> {
55
public static readonly CHANGE: string = 'change';
6+
public static readonly INPUT: string = 'input';
67
}

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

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ export class UUITextareaElement extends LabelMixin(
1717
) {
1818
static styles = [
1919
css`
20-
:host {
21-
display: flex;
22-
flex-direction: column;
23-
}
2420
:host([disabled]) .label,
25-
:host([disabled]) #char-count {
21+
:host([disabled]) #max-length-counter {
2622
color: var(--uui-interface-contrast-disabled);
2723
}
2824
:host([error]) textarea {
@@ -34,6 +30,11 @@ export class UUITextareaElement extends LabelMixin(
3430
:host([auto-height]) textarea {
3531
resize: none;
3632
}
33+
.label {
34+
display: inline-block;
35+
margin-bottom: var(--uui-size-1);
36+
font-weight: bold;
37+
}
3738
textarea[disabled] {
3839
cursor: not-allowed;
3940
background-color: var(
@@ -48,19 +49,30 @@ export class UUITextareaElement extends LabelMixin(
4849
4950
color: var(--uui-interface-contrast-disabled);
5051
}
51-
52-
#textarea {
52+
textarea {
53+
font-family: inherit;
54+
box-sizing: border-box;
5355
min-width: 100%;
5456
max-width: 100%;
57+
font-size: var(--uui-size-5);
58+
padding: var(--uui-size-2);
5559
border: 1px solid
5660
var(--uui-textarea-border-color, var(--uui-interface-border));
5761
border-radius: 0;
62+
outline: none;
5863
}
59-
#char-count {
64+
#lengths-container {
65+
display: flex;
66+
}
67+
#min-length-counter {
68+
color: var(--uui-look-danger-surface);
69+
margin-right: 1em;
70+
}
71+
#max-length-counter {
6072
display: inline-block;
6173
width: min-content;
6274
}
63-
#char-count.maxed {
75+
#max-length-counter.maxed {
6476
animation-name: maxed;
6577
animation-duration: 0.1s;
6678
animation-direction: alternate;
@@ -163,6 +175,15 @@ export class UUITextareaElement extends LabelMixin(
163175
@query('#textarea')
164176
protected _textarea!: HTMLInputElement;
165177

178+
/**
179+
* Defines the min length of the textarea.
180+
* @type {number}
181+
* @attr
182+
* @default undefined
183+
*/
184+
@property({ type: Number })
185+
minLength = 0;
186+
166187
/**
167188
* Defines the max length of the textarea.
168189
* @type {number}
@@ -201,6 +222,9 @@ export class UUITextareaElement extends LabelMixin(
201222

202223
private onInput(e: Event) {
203224
this.value = (e.target as HTMLInputElement).value;
225+
this.dispatchEvent(
226+
new UUITextareaEvent(UUITextareaEvent.INPUT, { bubbles: true })
227+
);
204228

205229
if (this.autoHeight) {
206230
this.autoUpdateHeight();
@@ -238,17 +262,26 @@ export class UUITextareaElement extends LabelMixin(
238262

239263
renderMaxLength() {
240264
return html`<span
241-
id="char-count"
265+
id="max-length-counter"
242266
class=${this.value.length >= this.maxLength! ? 'maxed' : ''}
243267
>${this.value ? this.value.length : 0}/${this.maxLength}</span
244268
>`;
245269
}
270+
renderMinLength() {
271+
const shouldRender = this.minLength - this.value.length > 0;
272+
return shouldRender
273+
? html`<span id="min-length-counter">
274+
${this.minLength - this.value.length}
275+
</span>`
276+
: '';
277+
}
246278

247279
render() {
248280
return html`
249281
${this.hideLabel === false ? this.renderLabel() : ''}
250282
<textarea
251283
maxlength=${ifDefined(this.maxLength > 0 ? this.maxLength : undefined)}
284+
minlength=${this.minLength}
252285
style="min-height: ${this.minHeight}; max-height: ${this.maxHeight}"
253286
id="textarea"
254287
.value=${this.value}
@@ -259,7 +292,10 @@ export class UUITextareaElement extends LabelMixin(
259292
@input=${this.onInput}
260293
@change=${this.onChange}>
261294
</textarea>
262-
${this.maxLength > 0 ? this.renderMaxLength() : ''}
295+
<div id="lengths-container">
296+
${this.minLength > 0 ? this.renderMinLength() : ''}
297+
${this.maxLength > 0 ? this.renderMaxLength() : ''}
298+
</div>
263299
`;
264300
}
265301
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const AAAOverview: Story = props =>
1515
html`<uui-textarea
1616
.label=${props.label}
1717
?auto-height=${props.autoHeight}
18+
.minLength=${props.minLength}
1819
.maxLength=${props.maxLength}
1920
.minHeight=${props.minHeight}
2021
.maxHeight=${props.maxHeight}

0 commit comments

Comments
 (0)