Skip to content
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
29 changes: 29 additions & 0 deletions packages/main/cypress/specs/DatePicker.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,36 @@ describe("Date Picker Tests", () => {
.should("have.attr", "placeholder", "test placeholder");
});

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

cy.get("[ui5-date-picker]")
.as("datePicker");

cy.get<DatePicker>("@datePicker")
.shadow()
.find("ui5-datetime-input")
.shadow()
.find(".ui5-input-clear-icon")
.should("exist");

cy.get<DatePicker>("@datePicker")
.shadow()
.find("ui5-datetime-input")
.shadow()
.find(".ui5-input-clear-icon-wrapper")
.click();

cy.get<DatePicker>("@datePicker")
.shadow()
.find("ui5-datetime-input")
.shadow()
.find(".ui5-input-clear-icon")
.should("not.exist");

cy.get<DatePicker>("@datePicker")
.should("have.value", "");
});

it("Selected date from daypicker is the same as datepicker date", () => {
cy.mount(<DatePicker value="Jan 29, 2019" formatPattern="MMM d, y"></DatePicker>);
Expand Down
18 changes: 18 additions & 0 deletions packages/main/src/DatePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ class DatePicker extends DateComponentBase implements IFormInputElement {
@property()
accessibleDescriptionRef?: string;

/**
* Defines whether the clear icon of the input will be shown.
* @default false
* @public
* @since 2.20.0
*/
@property({ type: Boolean })
showClearIcon = false;

@property({ type: Object })
_respPopoverConfig?: object;

Expand Down Expand Up @@ -660,6 +669,15 @@ class DatePicker extends DateComponentBase implements IFormInputElement {
this._updateValueAndFireEvents((e.target as DatePicker).value, false, ["input"], false);
}

_handleClearIconClick() {
this.value = "";
this._dateTimeInput.value = "";
this._updateValueState();
this._dateTimeInput.focus();
this.fireDecoratorEvent("change", { value: this.value, valid: true });
this.fireDecoratorEvent("value-changed", { value: this.value, valid: true });
}

/**
* Checks if the provided value is valid and within valid range.
* @protected
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/DatePickerInputTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function DatePickerInputTemplate(this: DatePicker) {
onInput={this._onInputInput}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we discuss this with team Rila in order to add custom event (e.g _clearIconClick) which to reuse here instead of checking inputType and etc?

Copy link
Contributor Author

@GDamyanov GDamyanov Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let's wait for the discussion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The additional logic was removed since we will update the value on onChange.

onui5-_request-submit={this._onInputRequestSubmit}
onKeyDown={this._onkeydown}
showClearIcon={this.showClearIcon}
>

{!this.open && this.valueStateMessage.length > 0 &&
Expand Down
5 changes: 5 additions & 0 deletions packages/main/src/themes/DatePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@

.ui5-date-picker-popover::part(header) {
padding: 0;
}

:host([show-clear-icon]) .ui5-date-picker-input:not([value]),
:host([show-clear-icon]) .ui5-date-picker-input[value=""] {
width: calc(100% + 36px);
}
6 changes: 6 additions & 0 deletions packages/main/src/themes/DateRangePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
min-width:inherit;
color: inherit;
background-color: inherit;
}

:host([show-clear-icon]) .ui5-date-picker-input:not([value]),
:host([show-clear-icon]) .ui5-date-picker-input[value=""] {
width: 100%;
min-width:inherit;
}
6 changes: 6 additions & 0 deletions packages/main/src/themes/DateTimePicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
min-width: inherit;
color: inherit;
background-color: inherit;
}

:host([show-clear-icon]) .ui5-date-picker-input:not([value]),
:host([show-clear-icon]) .ui5-date-picker-input[value=""] {
width: 100%;
min-width:inherit;
}
Loading
Loading