Skip to content

Commit 5fe7f4e

Browse files
MapTo0ilhan007
authored andcommitted
fix(ui5-ai-input): add docs and correct samples (#12643)
1 parent d9f3331 commit 5fe7f4e

File tree

6 files changed

+46
-39
lines changed

6 files changed

+46
-39
lines changed

packages/ai/cypress/specs/TextArea.cy.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("Basic", () => {
105105
cy.mount(
106106
<TextArea
107107
loading={false}
108-
currentVersion={1}
108+
currentVersion={2}
109109
totalVersions={3}
110110
onVersionChange={onVersionChange}
111111
/>
@@ -182,7 +182,7 @@ describe("Basic", () => {
182182
cy.mount(
183183
<TextArea
184184
loading={false}
185-
currentVersion={2}
185+
currentVersion={3}
186186
totalVersions={3}
187187
/>
188188
);
@@ -602,4 +602,4 @@ describe("Basic", () => {
602602
.should("not.exist");
603603
});
604604
});
605-
});
605+
});

packages/ai/cypress/specs/WritingAssistant.cy.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ describe("WritingAssistant Component", () => {
240240
.shadow()
241241
.find("[ui5-ai-versioning]")
242242
.should("exist")
243-
.should("have.prop", "currentStep", 2)
243+
.should("have.prop", "currentStep", 1)
244244
.should("have.prop", "totalSteps", 3);
245245

246246
cy.get("[ui5-ai-writing-assistant]")
@@ -255,7 +255,7 @@ describe("WritingAssistant Component", () => {
255255
cy.mount(
256256
<WritingAssistant
257257
loading={false}
258-
currentVersion={1}
258+
currentVersion={2}
259259
totalVersions={4}
260260
/>
261261
);
@@ -587,7 +587,7 @@ describe("WritingAssistant Component", () => {
587587
cy.mount(
588588
<WritingAssistant
589589
loading={false}
590-
currentVersion={1}
590+
currentVersion={2}
591591
totalVersions={4}
592592
onVersionChange={onVersionChange}
593593
/>
@@ -662,7 +662,7 @@ describe("WritingAssistant Component", () => {
662662
<WritingAssistant
663663
loading={false}
664664
promptDescription="Generated text"
665-
currentVersion={0}
665+
currentVersion={1}
666666
totalVersions={1}
667667
/>
668668
);
@@ -671,12 +671,12 @@ describe("WritingAssistant Component", () => {
671671
.as("toolbar")
672672
.invoke("prop", "loading", false)
673673
.invoke("prop", "promptDescription", "Multiple results")
674-
.invoke("prop", "currentVersion", 1)
674+
.invoke("prop", "currentVersion", 2)
675675
.invoke("prop", "totalVersions", 3);
676676

677677
cy.get("@toolbar")
678678
.should("have.prop", "loading", false)
679-
.should("have.prop", "currentVersion", 1)
679+
.should("have.prop", "currentVersion", 2)
680680
.should("have.prop", "totalVersions", 3);
681681

682682
cy.get("@toolbar")
@@ -796,7 +796,7 @@ describe("WritingAssistant Component", () => {
796796
cy.mount(
797797
<WritingAssistant
798798
loading={false}
799-
currentVersion={1}
799+
currentVersion={2}
800800
totalVersions={3}
801801
onVersionChange={cy.stub().as("onVersionChange")}
802802
onButtonClick={cy.stub().as("onButtonClick")}
@@ -1073,7 +1073,7 @@ describe("WritingAssistant Component", () => {
10731073
.shadow()
10741074
.find("[ui5-ai-versioning]")
10751075
.should("exist")
1076-
.should("have.prop", "currentStep", 3)
1076+
.should("have.prop", "currentStep", 2)
10771077
.should("have.prop", "totalSteps", 5);
10781078

10791079
cy.get("[ui5-ai-writing-assistant]")
@@ -1083,7 +1083,7 @@ describe("WritingAssistant Component", () => {
10831083
.find("ui5-ai-toolbar-label")
10841084
.shadow()
10851085
.find("span")
1086-
.should("contain.text", "3 / 5");
1086+
.should("contain.text", "2 / 5");
10871087
});
10881088

10891089
it("should maintain proper layout with all elements", () => {
@@ -1144,4 +1144,4 @@ describe("WritingAssistant Component", () => {
11441144
.should("have.prop", "loading", true);
11451145
});
11461146
});
1147-
});
1147+
});

packages/ai/src/Input.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from "@ui5/webcomponents-base/dist/Keys.js";
1010
import BaseInput from "@ui5/webcomponents/dist/Input.js";
1111
import type Menu from "@ui5/webcomponents/dist/Menu.js";
12+
import type { MenuItemClickEventDetail } from "@ui5/webcomponents/dist/Menu.js";
1213
import type Button from "./Button.js";
1314

1415
// styles
@@ -26,6 +27,10 @@ import {
2627
WRITING_ASSISTANT_GENERATING_ANNOUNCEMENT,
2728
} from "./generated/i18n/i18n-defaults.js";
2829

30+
type InputVersionChangeEventDetail = {
31+
backwards: boolean,
32+
};
33+
2934
/**
3035
* @class
3136
*
@@ -80,6 +85,11 @@ import {
8085
cancelable: true,
8186
})
8287

88+
/** Fired when an item from the AI actions menu is clicked.
89+
* @public
90+
*/
91+
@event("item-click")
92+
8393
/**
8494
* Fired when the user selects the "Stop" button to stop ongoing AI text generation.
8595
* @public
@@ -96,11 +106,10 @@ import {
96106

97107
class Input extends BaseInput {
98108
eventDetails!: BaseInput["eventDetails"] & {
99-
"version-change": {
100-
backwards: boolean;
101-
};
102-
"stop-generation": object;
103-
"button-click": object;
109+
"version-change": InputVersionChangeEventDetail;
110+
"stop-generation": void;
111+
"button-click": void;
112+
"item-click": MenuItemClickEventDetail;
104113
};
105114

106115
/**
@@ -246,15 +255,8 @@ class Input extends BaseInput {
246255
this._handleVersionChange(new CustomEvent("version-change", { detail: { backwards: false } }));
247256
}
248257

249-
_onMenuIconClick(): void {
250-
this.menu?.addEventListener("item-click", (e: Event) => {
251-
const customEvent = e as CustomEvent;
252-
this.dispatchEvent(new CustomEvent("item-click", {
253-
detail: customEvent.detail,
254-
bubbles: true,
255-
composed: true,
256-
}));
257-
});
258+
_onMenuIconClick(e: CustomEvent<MenuItemClickEventDetail>): void {
259+
this.fireDecoratorEvent("item-click", e.detail);
258260
}
259261

260262
/**
@@ -309,10 +311,11 @@ class Input extends BaseInput {
309311
}
310312

311313
get menu() {
312-
return this.shadowRoot?.querySelector("ui5-menu") as Menu;
314+
return this.shadowRoot?.querySelector("[ui5-menu]") as Menu;
313315
}
314316
}
315317

316318
Input.define();
317319

320+
export type { InputVersionChangeEventDetail, MenuItemClickEventDetail as InputItemClickEventDetail };
318321
export default Input;

packages/ai/src/TextArea.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import valueStateMessageStyles from "@ui5/webcomponents/dist/generated/themes/Va
1818
// Templates
1919
import TextAreaTemplate from "./TextAreaTemplate.js";
2020

21+
type TextAreaVersionChangeEventDetail = {
22+
backwards: boolean,
23+
};
24+
2125
/**
2226
* @class
2327
*
@@ -59,6 +63,7 @@ import TextAreaTemplate from "./TextAreaTemplate.js";
5963
/**
6064
* Fired when the user clicks on version navigation buttons.
6165
*
66+
* @param {boolean} backwards - Indicates if navigation is backwards (true) or forwards (false, default).
6267
* @public
6368
*/
6469
@event("version-change")
@@ -72,10 +77,8 @@ import TextAreaTemplate from "./TextAreaTemplate.js";
7277

7378
class TextArea extends BaseTextArea {
7479
eventDetails!: BaseTextArea["eventDetails"] & {
75-
"version-change": {
76-
backwards: boolean;
77-
};
78-
"stop-generation": object;
80+
"version-change": TextAreaVersionChangeEventDetail;
81+
"stop-generation": void;
7982
};
8083

8184
// Store bound handler for proper cleanup
@@ -242,4 +245,5 @@ class TextArea extends BaseTextArea {
242245

243246
TextArea.define();
244247

248+
export type { TextAreaVersionChangeEventDetail };
245249
export default TextArea;

packages/ai/src/WritingAssistantTemplate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function WritingAssistantTemplate(this: WritingAssistant) {
1818
>
1919
{isMultiResults && !this.loading && (
2020
<Versioning
21-
currentStep={this.currentVersion + 1}
21+
currentStep={this.currentVersion}
2222
totalSteps={this.totalVersions}
2323
onVersion-change={this.handleVersionChange}
2424
/>

packages/website/docs/_samples/ai/TextArea/Basic/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function animateTextGeneration(text) {
4747
function completeGeneration() {
4848
versionHistory.push({
4949
value: textarea.value,
50-
actionText: "Generated text",
50+
promptDescription: "Generated text",
5151
timestamp: new Date().toISOString()
5252
});
5353

@@ -57,11 +57,11 @@ function completeGeneration() {
5757
}
5858

5959
function updateComponentState() {
60-
textarea.currentVersionIndex = currentVersionIndex + 1;
60+
textarea.currentVersion = currentVersionIndex + 1;
6161
textarea.totalVersions = versionHistory.length;
6262

6363
if (versionHistory[currentVersionIndex]) {
64-
textarea.actionText = versionHistory[currentVersionIndex].actionText;
64+
textarea.promptDescription = versionHistory[currentVersionIndex].promptDescription;
6565
}
6666
}
6767

@@ -75,7 +75,7 @@ async function executeGeneration() {
7575

7676
// Set loading state
7777
textarea.loading = true;
78-
textarea.actionText = "Generating text...";
78+
textarea.promptDescription = "Generating text...";
7979

8080
try {
8181
// Simulate processing delay
@@ -92,7 +92,7 @@ async function executeGeneration() {
9292
} catch (error) {
9393
console.error('Generation failed:', error);
9494
textarea.loading = false;
95-
textarea.actionText = 'Generation failed';
95+
textarea.promptDescription = 'Generation failed';
9696
}
9797
}
9898

@@ -107,7 +107,7 @@ function stopGeneration() {
107107
if (textarea.value.trim()) {
108108
versionHistory.push({
109109
value: textarea.value,
110-
actionText: "Generated text (stopped)",
110+
promptDescription: "Generated text (stopped)",
111111
timestamp: new Date().toISOString()
112112
});
113113

0 commit comments

Comments
 (0)