Skip to content

Commit e10575d

Browse files
authored
fix(ui5-textarea): enhance storybook samples (#7443)
* fix(ui5-textarea): enhance storybook samples * fix(ui5-textarea): apply review comments
1 parent d512116 commit e10575d

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

packages/main/src/TextArea.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,7 @@ class TextArea extends UI5Element implements IFormElement {
176176
/**
177177
* Defines the value state of the component.
178178
* <br><br>
179-
* Available options are:
180-
* <ul>
181-
* <li><code>None</code></li>
182-
* <li><code>Error</code></li>
183-
* <li><code>Warning</code></li>
184-
* <li><code>Success</code></li>
185-
* <li><code>Information</code></li>
186-
* </ul>
187-
* <br><br>
179+
*
188180
* <b>Note:</b> If <code>maxlength</code> property is set,
189181
* the component turns into "Warning" state once the characters exceeds the limit.
190182
* In this case, only the "Error" state is considered and can be applied.

packages/playground/_stories/main/TextArea/TextArea.stories.ts

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { html } from "lit";
22
import { ifDefined } from "lit/directives/if-defined.js";
3+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
34

45
import type { Meta, StoryFn } from "@storybook/web-components";
56

@@ -15,7 +16,7 @@ const component = "ui5-textarea";
1516
let index = 0;
1617

1718
export default {
18-
title: "Main/TextArea",
19+
title: "Main/Text Area",
1920
component: "TextArea",
2021
parameters: {
2122
docs: {
@@ -42,35 +43,51 @@ const Template: UI5StoryArgs<TextArea, StoryArgsSlots> = (args) => html`
4243
name="${ifDefined(args.name)}"
4344
accessible-name="${ifDefined(args.accessibleName)}"
4445
accessible-name-ref="${ifDefined(args.accessibleNameRef)}"
45-
></ui5-textarea>`;
46+
>
47+
${unsafeHTML(args.valueStateMessage)}
48+
</ui5-textarea>`;
4649

47-
export const BasicTextArea = Template.bind({});
48-
BasicTextArea.args = {
49-
placeholder: 'Type as much text as you wish',
50+
export const Basic = Template.bind({});
51+
Basic.args = {
52+
placeholder: 'Enter text',
5053
};
5154

52-
export const TextAreaMaxLength = Template.bind({});
53-
TextAreaMaxLength.args = {
54-
placeholder: 'Type no more than 10 symbols',
55+
56+
export const WithMaxLength = Template.bind({});
57+
WithMaxLength.decorators = [
58+
(story) => html`
59+
${story()}
60+
<script>
61+
(() => {
62+
const textAreaMaxLength = document.getElementById("textArea-${index-1}");
63+
64+
textAreaMaxLength.addEventListener("input", function (event) {
65+
const { value, maxlength} = textAreaMaxLength;
66+
textAreaMaxLength.valueState = value.length > maxlength ? "Warning" : "None";
67+
});
68+
})()
69+
</script>`
70+
];
71+
WithMaxLength.args = {
72+
placeholder: 'Enter text',
5573
maxlength: 10,
56-
showExceededText: true
74+
showExceededText: true,
75+
valueStateMessage: `<div id="warningMessage" slot="valueStateMessage">The characters limit is exceeded</div>`
5776

5877
};
59-
TextAreaMaxLength.storyName = "Text Area with Maximum Length";
6078

61-
export const TextAreaLabel = Template.bind({});
62-
TextAreaLabel.decorators = [
79+
export const WithLabel = Template.bind({});
80+
WithLabel.decorators = [
6381
(story) => {
6482
return html`
6583
<ui5-label for="textArea-${index}">Description</ui5-label>
6684
${story()}
6785
`;
6886
}
6987
]
70-
TextAreaLabel.args = {
88+
WithLabel.args = {
7189
placeholder: 'Enter description',
7290
required: true
73-
7491
};
7592

7693

0 commit comments

Comments
 (0)