Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TextArea): adding warn, warnText properties to TextArea #978

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/src/COMPONENT_API.json
Original file line number Diff line number Diff line change
Expand Up @@ -11393,6 +11393,28 @@
"constant": false,
"reactive": false
},
{
"name": "warn",
"kind": "let",
"description": "Set to `true` to indicate an warning state",
"type": "boolean",
"value": "false",
"isFunction": false,
"isFunctionDeclaration": false,
"constant": false,
"reactive": false
},
{
"name": "warnText",
"kind": "let",
"description": "Specify the warning state text",
"type": "string",
"value": "\"\"",
"isFunction": false,
"isFunctionDeclaration": false,
"constant": false,
"reactive": false
},
{
"name": "id",
"kind": "let",
Expand Down
4 changes: 4 additions & 0 deletions docs/src/pages/components/TextArea.svx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ components: ["TextArea", "TextAreaSkeleton"]

<TextArea invalid invalidText="Only plain text characters are allowed" labelText="App description" placeholder="Enter a description..." />

### Warning state

<TextArea warn warnText="It is recommended to enter a longer description" labelText="App description" placeholder="Enter a description..." />

### Disabled state

<TextArea disabled labelText="App description" placeholder="Enter a description..." />
Expand Down
25 changes: 23 additions & 2 deletions src/TextArea/TextArea.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
/** Specify the text for the invalid state */
export let invalidText = "";

/** Set to `true` to indicate an warning state */
export let warn = false;

/** Specify the warning state text */
export let warnText = "";

/** Set an id for the textarea element */
export let id = "ccs-" + Math.random().toString(36);

Expand All @@ -45,8 +51,10 @@
export let ref = null;

import WarningFilled16 from "../icons/WarningFilled16.svelte";
import WarningAltFilled16 from "../icons/WarningAltFilled16.svelte";

$: errorId = `error-${id}`;
$: warnId = `warn-${id}`;
</script>

<!-- svelte-ignore a11y-mouse-events-have-key-events -->
Expand All @@ -72,14 +80,23 @@
<div
class:bx--text-area__wrapper="{true}"
data-invalid="{invalid || undefined}"
data-warn="{warn || undefined}"
>
{#if invalid}
<WarningFilled16 class="bx--text-area__invalid-icon" />
{/if}
{#if !invalid && warn}
<WarningAltFilled16
class="bx--text-area__invalid-icon
bx--text-area__invalid-icon--warning"
/>
{/if}
<textarea
bind:this="{ref}"
data-invalid="{invalid || undefined}"
aria-invalid="{invalid || undefined}"
aria-describedby="{invalid ? errorId : undefined}"
data-warn="{warn || undefined}"
aria-describedby="{invalid ? errorId : warn ? warnId : undefined}"
disabled="{disabled}"
id="{id}"
name="{name}"
Expand All @@ -90,6 +107,7 @@
class:bx--text-area="{true}"
class:bx--text-area--light="{light}"
class:bx--text-area--invalid="{invalid}"
class:bx--text-area--warn="{warn}"
{...$$restProps}
readonly="{$$restProps.readonly === true ? true : undefined}"
on:change
Expand All @@ -102,7 +120,7 @@
on:focus
on:blur></textarea>
</div>
{#if !invalid && helperText}
{#if !invalid && !warn && helperText}
<div
class:bx--form__helper-text="{true}"
class:bx--form__helper-text--disabled="{disabled}"
Expand All @@ -113,4 +131,7 @@
{#if invalid}
<div id="{errorId}" class:bx--form-requirement="{true}">{invalidText}</div>
{/if}
{#if !invalid && warn}
<div id="{warnId}" class:bx--form-requirement="{true}">{warnText}</div>
{/if}
</div>