SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.56k stars 267 forks source link

ui5-datetime-picker: "Error" value-state cleared on change #4684

Closed ee92 closed 2 years ago

ee92 commented 2 years ago

Bug Description

The datetime picker reverts "Error" value-state back to "None" when a valid date is selected. This only happens for "Error" and not for "Warning", "Information", or "Success".

Expected Behavior

Expect to be able to set the valueState to "Error" programmatically based on custom validation, without the component reverting it to "None" for what it considers is a valid date.

Steps to Reproduce

Steps to reproduce the behavior:

  1. Go to https://codesandbox.io/s/ui5-webcomponents-forked-bp70dk
  2. Select a date using the date picker
  3. Notice in the console the value-state gets overridden from "Error" to "None"

Context

Priority

Stakeholder Info (if applicable)

Thanks for taking a look!

MarcusNotheis commented 2 years ago

Thanks for reporting! I'll forward this issue to our UI5 Web Components Colleagues as the affected component is developed in their repository.

ilhan007 commented 2 years ago

Can you check this issue @SAP/ui5-webcomponents-topic-b it is reproducible although the sample is with the react wrappers. I think it won't take much to re-create it with pure ui5-webcomps.

eswortmaler commented 2 years ago

Here is a demonstration of the issue with pure ui5-webcomponents https://codesandbox.io/s/ui5-webcomponents-forked-l8e24?file=/src/index.js

The breaking change seems to have been introduced between 1.0.0-rc.15 and 1.0.0-rc.16 The linked example works as expected when choosing @ui5/webcomponents 1.0.0-rc.15

ee92 commented 2 years ago

The issue seems to be caused by this line: https://github.com/SAP/ui5-webcomponents/blob/master/packages/main/src/DatePicker.js#L549 (Error value state being changed to None)

Is there any update on a fix?

tsanislavgatev commented 2 years ago

Hello @ee92 ,

Sorry for the late response!

Have you tried to prevent the default behaviour of the control? The change and input events of the DatePicker are preventable, this will prevent the change of the value and the internal verification, so you will have the full control over the value change and the value state change. You will still receive the value in the event and that the value is changed, but if you prevent it, the value and the value state won't be touched by the control itself.

Can you please verify if this will fix your issue?

Best Regards, Tsanislav

ee92 commented 2 years ago

@tsanislavgatev the issue is not fixed by using preventDefault on the event. This line still runs and causes the valueState to be changed to "None" https://github.com/SAP/ui5-webcomponents/blob/master/packages/main/src/DatePicker.js#L558

tsanislavgatev commented 2 years ago

https://user-images.githubusercontent.com/11508737/165468611-9fb54231-ed00-4cfd-b68a-3e1b6756845a.mov

@ee92 Hello, I've made a quick recording of both cases.

The method you are refering to is called after we check if the event is prevented. https://github.com/SAP/ui5-webcomponents/blob/532d676c367832542ba469c45643f686a03a0168/packages/main/src/DatePicker.js#L540

And then called here: https://github.com/SAP/ui5-webcomponents/blob/532d676c367832542ba469c45643f686a03a0168/packages/main/src/DatePicker.js#L549

Can you please check the behaviour again? And if still failing, to provide an example again so I can investigate.

Best Regards, Tsanislav

ee92 commented 2 years ago

@tsanislavgatev

This is true for DatePicker, but not for DateTimePicker. I updated the ticket description with a new sandbox that uses DateTimePicker instead.

Just by looking at the code you can see this line runs unconditionally: https://github.com/SAP/ui5-webcomponents/blob/3236d56bee43eb8d1e31bb3a59499226889e95bf/packages/main/src/DateTimePicker.js#L373

We had no issue with this previous to upgrading to 1.x.x so hoping that the solution does not require preventing the event.

Thanks

tsanislavgatev commented 2 years ago

Hello,

The change that introduced the secondary check is to improve the checks that the component provides. The control itself provides a bahaviour with predefined validations of dates, ranges, formats of date/time. It comes by default with the control, that's why you receive this removing of the value state. Because of this we've introduced the preventable behaviour, for the developers who don't need our checks, to give them the opportunity to implement their validation and value setting. That's why we are talking about preventing the default behaviour and why we decided to provide a full control option.

Best Regards, Tsanislav