Skip to content

Commit b6af601

Browse files
wolfibDevtools-frontend LUCI CQ
authored andcommitted
[Freestyler] Disable submit button when input is empty
Bug: https://crbug.com/374662092 Change-Id: Iecc2c6648c696f8787b8c0457e960ea39278ed66 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5942732 Reviewed-by: Ergün Erdoğmuş <[email protected]> Commit-Queue: Ergün Erdoğmuş <[email protected]> Auto-Submit: Wolfgang Beyer <[email protected]>
1 parent 7394fd2 commit b6af601

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

front_end/panels/freestyler/components/ProvideFeedback.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describeWithEnvironment('ProvideFeedback', () => {
1717

1818
assert(component.shadowRoot!.querySelector('.feedback-form'));
1919
});
20+
2021
it('should not show the feedback form when canShowFeedbackForm is false', async () => {
2122
const component = new Freestyler.ProvideFeedback({onFeedbackSubmit: sinon.stub(), canShowFeedbackForm: false});
2223
renderElementIntoDOM(component);
@@ -26,4 +27,19 @@ describeWithEnvironment('ProvideFeedback', () => {
2627

2728
assert.notExists(component.shadowRoot!.querySelector('.feedback-form'));
2829
});
30+
31+
it('should disable the submit button when the input is empty', async () => {
32+
const component = new Freestyler.ProvideFeedback({onFeedbackSubmit: sinon.stub(), canShowFeedbackForm: true});
33+
renderElementIntoDOM(component);
34+
const button = component.shadowRoot!.querySelector('.rate-buttons devtools-button')! as HTMLElement;
35+
button.click();
36+
37+
assert(component.shadowRoot!.querySelector('.feedback-form'));
38+
const submitButton = component.shadowRoot!.querySelector('[aria-label="Submit"]') as HTMLButtonElement;
39+
assert.isTrue(submitButton?.disabled);
40+
const inputField = component.shadowRoot!.querySelector('.feedback-form input')! as HTMLInputElement;
41+
inputField.value = 'test';
42+
inputField.dispatchEvent(new Event('input'));
43+
assert.isFalse(submitButton?.disabled);
44+
});
2945
});

front_end/panels/freestyler/components/ProvideFeedback.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export class ProvideFeedback extends HTMLElement {
7171
#props: ProvideFeedbackProps;
7272
#isShowingFeedbackForm = false;
7373
#currentRating?: Host.AidaClient.Rating;
74+
#isSubmitButtonDisabled = true;
7475

7576
constructor(props: ProvideFeedbackProps) {
7677
super();
@@ -164,6 +165,15 @@ export class ProvideFeedback extends HTMLElement {
164165
// clang-format on
165166
}
166167

168+
#handleInputChange = (event: KeyboardEvent): void => {
169+
const value = (event.target as HTMLInputElement).value;
170+
const disableSubmit = !value;
171+
if (disableSubmit !== this.#isSubmitButtonDisabled) {
172+
this.#isSubmitButtonDisabled = disableSubmit;
173+
this.#render();
174+
}
175+
};
176+
167177
#renderFeedbackForm(): LitHtml.LitTemplate {
168178
// clang-format off
169179
return html`
@@ -189,6 +199,7 @@ export class ProvideFeedback extends HTMLElement {
189199
<input
190200
type="text"
191201
class="devtools-text-input feedback-input"
202+
@input=${this.#handleInputChange}
192203
placeholder=${lockedString(
193204
UIStringsNotTranslate.provideFeedbackPlaceholder,
194205
)}
@@ -202,6 +213,7 @@ export class ProvideFeedback extends HTMLElement {
202213
.data=${
203214
{
204215
type: 'submit',
216+
disabled: this.#isSubmitButtonDisabled,
205217
variant: Buttons.Button.Variant.OUTLINED,
206218
size: Buttons.Button.Size.SMALL,
207219
title: lockedString(UIStringsNotTranslate.submit),

0 commit comments

Comments
 (0)