Skip to content

Commit 367d607

Browse files
committed
feat(text-area): add warn and warnText props
Closes #1136
1 parent cc65ac2 commit 367d607

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

COMPONENT_INDEX.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,6 +4082,8 @@ None.
40824082
| hideLabel | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text |
40834083
| invalid | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to indicate an invalid state |
40844084
| invalidText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the text for the invalid state |
4085+
| warn | No | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to indicate a warning state |
4086+
| warnText | No | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the warning state text |
40854087
| id | No | <code>let</code> | No | <code>string</code> | <code>"ccs-" + Math.random().toString(36)</code> | Set an id for the textarea element |
40864088
| name | No | <code>let</code> | No | <code>string</code> | <code>undefined</code> | Specify a name attribute for the input |
40874089

docs/src/COMPONENT_API.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15424,6 +15424,30 @@
1542415424
"constant": false,
1542515425
"reactive": false
1542615426
},
15427+
{
15428+
"name": "warn",
15429+
"kind": "let",
15430+
"description": "Set to `true` to indicate a warning state",
15431+
"type": "boolean",
15432+
"value": "false",
15433+
"isFunction": false,
15434+
"isFunctionDeclaration": false,
15435+
"isRequired": false,
15436+
"constant": false,
15437+
"reactive": false
15438+
},
15439+
{
15440+
"name": "warnText",
15441+
"kind": "let",
15442+
"description": "Specify the warning state text",
15443+
"type": "string",
15444+
"value": "\"\"",
15445+
"isFunction": false,
15446+
"isFunctionDeclaration": false,
15447+
"isRequired": false,
15448+
"constant": false,
15449+
"reactive": false
15450+
},
1542715451
{
1542815452
"name": "id",
1542915453
"kind": "let",

src/TextArea/TextArea.svelte

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
/** Specify the text for the invalid state */
4545
export let invalidText = "";
4646
47+
/** Set to `true` to indicate a warning state */
48+
export let warn = false;
49+
50+
/** Specify the warning state text */
51+
export let warnText = "";
52+
4753
/** Set an id for the textarea element */
4854
export let id = "ccs-" + Math.random().toString(36);
4955
@@ -57,8 +63,10 @@
5763
export let ref = null;
5864
5965
import WarningFilled from "../icons/WarningFilled.svelte";
66+
import WarningAltFilled from "../icons/WarningAltFilled.svelte";
6067
6168
$: errorId = `error-${id}`;
69+
$: warnId = `warn-${id}`;
6270
</script>
6371

6472
<!-- svelte-ignore a11y-mouse-events-have-key-events -->
@@ -90,15 +98,26 @@
9098
{/if}
9199
</div>
92100
{/if}
93-
<div class:bx--text-area__wrapper={true} data-invalid={invalid || undefined}>
101+
<div
102+
class:bx--text-area__wrapper={true}
103+
data-invalid={invalid || undefined}
104+
data-warn={warn || undefined}
105+
>
94106
{#if invalid}
95107
<WarningFilled class="bx--text-area__invalid-icon" />
96108
{/if}
109+
{#if !invalid && warn}
110+
<WarningAltFilled
111+
class="bx--text-area__invalid-icon
112+
bx--text-area__invalid-icon--warning"
113+
/>
114+
{/if}
97115
<textarea
98116
bind:this={ref}
99117
bind:value
100118
aria-invalid={invalid || undefined}
101-
aria-describedby={invalid ? errorId : undefined}
119+
aria-describedby={invalid ? errorId : warn ? warnId : undefined}
120+
data-warn={warn || undefined}
102121
{disabled}
103122
{id}
104123
{name}
@@ -109,6 +128,7 @@
109128
class:bx--text-area={true}
110129
class:bx--text-area--light={light}
111130
class:bx--text-area--invalid={invalid}
131+
class:bx--text-area--warning={warn}
112132
maxlength={maxCount ?? undefined}
113133
{...$$restProps}
114134
on:change
@@ -120,7 +140,7 @@
120140
on:paste
121141
></textarea>
122142
</div>
123-
{#if !invalid && helperText}
143+
{#if !invalid && !warn && helperText}
124144
<div
125145
class:bx--form__helper-text={true}
126146
class:bx--form__helper-text--disabled={disabled}
@@ -131,4 +151,7 @@
131151
{#if invalid}
132152
<div id={errorId} class:bx--form-requirement={true}>{invalidText}</div>
133153
{/if}
154+
{#if !invalid && warn}
155+
<div id={warnId} class:bx--form-requirement={true}>{warnText}</div>
156+
{/if}
134157
</div>

types/TextArea/TextArea.svelte.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ type $Props = {
8282
*/
8383
invalidText?: string;
8484

85+
/**
86+
* Set to `true` to indicate a warning state
87+
* @default false
88+
*/
89+
warn?: boolean;
90+
91+
/**
92+
* Specify the warning state text
93+
* @default ""
94+
*/
95+
warnText?: string;
96+
8597
/**
8698
* Set an id for the textarea element
8799
* @default "ccs-" + Math.random().toString(36)

0 commit comments

Comments
 (0)