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

Fix/slider input validation #65

Merged
merged 91 commits into from
Sep 6, 2022
Merged

Fix/slider input validation #65

merged 91 commits into from
Sep 6, 2022

Conversation

jamesducky
Copy link
Contributor

Closes [BUG] Slider - Number input validation too restrictive
Matches updated UX spec

Changes

  • Number Input field now validates on blur, not on change
  • Refactors valid input to be called once, and set in state.
  • Refactors validation logic to remove variable mutation
  • Calls the permitted input range in state once

Issues

  • Tests for update validation removed as validation does not happen until blur on input. Stencil e2e does not provide a way to trigger the blur event. Unable to find work around.

@github-actions
Copy link

github-actions bot commented Aug 11, 2022

Visit the preview URL for this PR (updated for commit 1d21a85):

https://test-auth-d13f2--pr65-fix-slider-2-fvnsnvtu.web.app

(expires Tue, 13 Sep 2022 08:37:29 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@nathan-bird nathan-bird changed the title Fix/slider 2 Fix/slider input validation Aug 11, 2022
@nathan-bird
Copy link
Contributor

nathan-bird commented Aug 15, 2022

Tests for update validation removed as validation does not happen until blur on input. Stencil e2e does not provide a way to trigger the blur event. Unable to find work around.

Since Stencil 2.17.2 they have added a mock blur to their event api.
I suggest asking other Plumage devs on how to update the package and how best to try and use this api to write the tests you want.

Copy link
Contributor

@nathan-bird nathan-bird left a comment

Choose a reason for hiding this comment

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

The input field is not populated with a value on render, it is only updated on slider change.
Screenshot 2022-08-15 at 07 18 39

Keyboard navigation is difficult/impossible.

  • Hitting enter when focused on input field does not set the value
  • Entering a number starts with an invalid value forces the user out of focus. To repeat; go to Stepped story, tab into the input field, try to type "15". After entering "1" focus will be removed and the slider will move to 5.

@jamesducky
Copy link
Contributor Author

  • Entering a number starts with an invalid value forces the user out of focus. To repeat; go to Stepped story, tab into the input field, try to type "15". After entering "1" focus will be removed and the slider will move to 5.

I think you'll only see this in storybook, not in the React example. The reason is the default keyboard shortcuts in storybook shift focus.
Screenshot 2022-08-15 at 08 27 59

@jamesducky
Copy link
Contributor Author

jamesducky commented Sep 2, 2022

Updates

  • merged react app example to include tab
  • fixed a bug) - zero is a falsey value causing new value to be rejected
  • as switching tabs causes the values to reset, lifted state up to parent component (tab). (Pasing the value update function as props to the child )

Copy link
Contributor

@nathan-bird nathan-bird left a comment

Choose a reason for hiding this comment

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

A few comments for you to check out

Reset
</PlmgButton>
<label>{SLIDERS.stepped.label}</label>
<PlmgSlider
Copy link
Contributor

Choose a reason for hiding this comment

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

On first render I am seeing thumb label positioning problems.
Screenshot 2022-09-05 at 03 28 36
I have seen this happen on all the sliders, it does not appear to be unique to the decimal slider.

Copy link
Contributor Author

@jamesducky jamesducky Sep 5, 2022

Choose a reason for hiding this comment

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

// Using min-width
Screenshot 2022-09-05 at 09 04 40

Managed to recreate the bug by putting a fixed width on the slider (240px).
The input field is actually set by the 'size' value, which is specified by the max value of the input number field. Forcing a min-width on the input field changes the input field, causing the input field to change size and making it overflow its container.
Using an outline is also causing an additional overflow.
Fix: removed min-width, added a negative outline-offset on the input field
// Without min-width
Screenshot 2022-09-05 at 09 07 20
The reason I was using min-width was to make the input field match the design.

Copy link
Contributor Author

@jamesducky jamesducky Sep 5, 2022

Choose a reason for hiding this comment

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

The 'track value' (the input range slider container's) width was getting changed between rendering the component container and calculating the thumb position because of flex gap and fit-content. Changing flex gap for margin-left with a fixed value and removing fit-content prevents input from rendering.

@jamesducky
Copy link
Contributor Author

jamesducky commented Sep 5, 2022

@nathan-bird: I've added a prop to allow the user to control textInputWidth. This is not because of the thumb positioning issue, which I've fixed separately, but I think we need this to control to maintain visual consistency. As discussed in the spec.

Copy link
Contributor

@nathan-bird nathan-bird left a comment

Choose a reason for hiding this comment

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

Updates look ok. Would be nice with a test of the new control.

Copy link
Contributor

@nathan-bird nathan-bird left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Next time something like this could be many smaller PRs which would make it faster to review and merge.

@nathan-bird nathan-bird merged commit 3f972f7 into main Sep 6, 2022
@nathan-bird nathan-bird deleted the fix/slider-2 branch September 6, 2022 10:48
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.

2 participants