Skip to content

Commit 89ccfb8

Browse files
authored
feat(ui5-date-picker, ui5-daterange-picket, ui5-datetime-picker): introduce show-clear-icon property
Introduces a new show-clear-icon property to the DatePicker, DateRangePicker and DateTimePicker components that displays a clear icon inside the input field. When clicked, the icon clears the input value. Changes: Added boolean property (default: false, since: 2.20.0) Clear icon automatically shows when there's a value and hides when empty, readonly, or disabled Clicking the clear icon clears the value, focuses the input, and fires change events
1 parent 85c6c73 commit 89ccfb8

22 files changed

Lines changed: 161 additions & 401 deletions

File tree

packages/main/cypress/specs/DatePicker.cy.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,38 @@ describe("Date Picker Tests", () => {
201201
.should("have.attr", "placeholder", "test placeholder");
202202
});
203203

204+
it("clear icon", () => {
205+
cy.mount(<DatePicker showClearIcon={true} value="Jan 1, 2020" formatPattern="MMM d, y"></DatePicker>);
204206

207+
cy.get("[ui5-date-picker]")
208+
.as("datePicker");
209+
210+
cy.get<DatePicker>("@datePicker")
211+
.shadow()
212+
.find("ui5-datetime-input")
213+
.shadow()
214+
.find(".ui5-input-clear-icon")
215+
.should("exist");
216+
217+
cy.get<DatePicker>("@datePicker")
218+
.shadow()
219+
.find("ui5-datetime-input")
220+
.shadow()
221+
.find(".ui5-input-clear-icon-wrapper")
222+
.click();
223+
224+
cy.get<DatePicker>("@datePicker")
225+
.shadow()
226+
.find("ui5-datetime-input")
227+
.shadow()
228+
.find(".ui5-input-clear-icon")
229+
.should("not.exist");
230+
231+
cy.realPress("Tab");
232+
233+
cy.get<DatePicker>("@datePicker")
234+
.should("have.value", "");
235+
});
205236

206237
it("Selected date from daypicker is the same as datepicker date", () => {
207238
cy.mount(<DatePicker value="Jan 29, 2019" formatPattern="MMM d, y"></DatePicker>);

packages/main/src/DatePicker.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,15 @@ class DatePicker extends DateComponentBase implements IFormInputElement {
367367
@property()
368368
accessibleDescriptionRef?: string;
369369

370+
/**
371+
* Defines whether the clear icon of the input will be shown.
372+
* @default false
373+
* @public
374+
* @since 2.20.0
375+
*/
376+
@property({ type: Boolean })
377+
showClearIcon = false;
378+
370379
@property({ type: Object })
371380
_respPopoverConfig?: object;
372381

packages/main/src/DatePickerInputTemplate.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default function DatePickerInputTemplate(this: DatePicker) {
2828
onInput={this._onInputInput}
2929
onui5-_request-submit={this._onInputRequestSubmit}
3030
onKeyDown={this._onkeydown}
31+
showClearIcon={this.showClearIcon}
3132
>
3233

3334
{!this.open && this.valueStateMessage.length > 0 &&

packages/main/src/themes/DatePicker.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
}
4242

4343
:host .ui5-date-picker-input {
44-
width: 100%;
4544
color: inherit;
4645
background-color: inherit;
4746
border-radius: inherit;
@@ -63,4 +62,5 @@
6362

6463
.ui5-date-picker-popover::part(header) {
6564
padding: 0;
66-
}
65+
}
66+

packages/main/src/themes/DateTimePicker.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
}
66

77
:host .ui5-date-picker-input {
8+
width: 100%;
89
min-width: inherit;
910
color: inherit;
1011
background-color: inherit;
12+
1113
}

0 commit comments

Comments
 (0)