Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INSTUI-4429 fix(ui-time-select): clear input field after setting an empty value #1848

Conversation

ToMESSKa
Copy link
Contributor

@ToMESSKa ToMESSKa commented Jan 21, 2025

ISSUE:
In the TimeSelect component, after explicitly setting a value, it cannot be cleared from the input field. When the value is deleted form the input filed and the input field loses focus, the last selected option is reapplied.
Also the onChange does not trigger when input field is cleared.

TEST PLAN:

test clearing values if allowClearingSelection is not set (should default to false)

  • go to the "Controlled" TimeSelect example
  • before selecting a new value, click the input field, delete its current value, and click elsewhere to ensure the input field loses focus
  • the input value should go back to the initial value (11:59:00 PM) and onChange should not triggered (can be checked with a console.log)
  • reload the same example
  • select a new value from the dropdown
  • after it' selected, click the input field, delete its current value, and click elsewhere to ensure the input field loses focus
  • the input value should go back to the previously selected value and onChange should not triggered (can be checked with a console.log)

test clearing values if allowClearingSelection is true:

  • go to the "Controlled" TimeSelect example
  • set allowClearingSelection to true
  • before selecting a new value, click the input field, delete its current value, and click elsewhere to ensure the input field loses focus
  • the input field now should be cleared and have no option selected apart form the placeholder
  • onChange should be triggered when input is cleared and loses focus (can be checked with a console.log)
  • reload the same example and set allowClearingSelection to true
  • select a different value than the current one
  • click the input field, delete its current value, and click elsewhere to ensure the input field loses focus
  • the input field now should be cleared and have no option selected apart form the placeholder
  • onChange should be triggered when input is cleared and loses focus (can be checked with a console.log)

other:

  • test of all the other examples in TimeSelect to see if they work as expected
  • review the new test

Copy link

github-actions bot commented Jan 21, 2025

PR Preview Action v1.6.0
Preview removed because the pull request was closed.
2025-02-03 13:04 UTC

@ToMESSKa ToMESSKa self-assigned this Jan 22, 2025
@ToMESSKa ToMESSKa force-pushed the INSTUI-4429_time_select_unable_to_clear_field_after_setting_a_value branch from 7451c89 to c4c66a9 Compare January 23, 2025 09:53
@ToMESSKa ToMESSKa marked this pull request as ready for review January 23, 2025 10:00
@ToMESSKa ToMESSKa requested a review from matyasf January 23, 2025 10:00
@matyasf matyasf changed the title fix(ui-time-select): clear input field after setting an empty value INSTUI-4429 fix(ui-time-select): clear input field after setting an empty value Jan 24, 2025
Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

Nice work!
I think that this new behaviour is much more logical, than the old one. (and the old one was even buggy in the uncontrolled behaviour because you could clear the field when the value was not cleared.)

But I'm afraid that introducing this as a fix could break our user's code, since until now it was impossible for the component to return '' as value, it always returned a valid date.
So can you please put this behind a new prop, say allowClearingSelection (it should default to false) to make sure we dont break code?
Also we could make this new behaviour the default one in the next major version, so please add this to our v11-upgrade-guide.md.

PS I could clear the input with just keyboard, what is the a11y concern here?

@ToMESSKa ToMESSKa force-pushed the INSTUI-4429_time_select_unable_to_clear_field_after_setting_a_value branch from c4c66a9 to 7cf710f Compare January 29, 2025 15:22
@ToMESSKa
Copy link
Contributor Author

ToMESSKa commented Jan 29, 2025

Nice work! I think that this new behaviour is much more logical, than the old one. (and the old one was even buggy in the uncontrolled behaviour because you could clear the field when the value was not cleared.)

But I'm afraid that introducing this as a fix could break our user's code, since until now it was impossible for the component to return '' as value, it always returned a valid date. So can you please put this behind a new prop, say allowClearingSelection (it should default to false) to make sure we dont break code? Also we could make this new behaviour the default one in the next major version, so please add this to our v11-upgrade-guide.md.

PS I could clear the input with just keyboard, what is the a11y concern here?

@matyasf

  • introduced the allowClearingSelection and updated the test plan, please check them again
  • what is additional fix now is that in the previous version if you clear the input field right after the first render and before selecting anything new, the input field is cleared (but the value is not updated to ''). What I did was (without setting allowClearingSelection to true) is that now clearing the initial input value results in displaying the initial value again (11:59:00 PM) - I think it a reasonable fix but please let me know if it can have any unwanted results and it should be left out
  • I updated the v11 documentation too
  • as for the a11y issue, if you set allowClearingSelection to true and clear the input value and press Enter, it selects the first option. You can still exit the input field with a Tab, but we @git-nandor and I were not sure if tabbing is a usual user behavior in this case (that why we mentioned an empty first option?)

Copy link
Contributor

@joyenjoyer joyenjoyer left a comment

Choose a reason for hiding this comment

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

nice work

Copy link
Collaborator

@matyasf matyasf left a comment

Choose a reason for hiding this comment

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

as for the a11y issue, if you set allowClearingSelection to true and clear the input value and press Enter, it selects the first option. You can still exit the input field with a Tab, but were not sure if tabbing is a usual user behavior in this case

I think that this is fine. We clearly indicate that there is a selection, and Enter confirms it. It might be better if we would not select anything, but thats out of scope for this PR IMO.

@matyasf matyasf merged commit 1993282 into master Feb 3, 2025
10 of 11 checks passed
@matyasf matyasf deleted the INSTUI-4429_time_select_unable_to_clear_field_after_setting_a_value branch February 3, 2025 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants