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: allow "0%" snap points #278

Merged
merged 1 commit into from
Feb 14, 2021
Merged

Conversation

richkeenan
Copy link

@richkeenan richkeenan commented Feb 11, 2021

Motivation

I setup my snap points using percentages, ["0%", "10%", "60%"] but got an error saying

Invariant Violation: '0%' is not a valid percentage snap point! expected percentage snap point must be only numbers and '%'. e.g. '50%'.

This is because the invariant uses the result of the Number constructor on the part before the percentage sign - which returns 0 here which is falsey.

This is easily fixed by using the number 0 rather than the string percentage but it took me a minute or two to realise I could mix numbers and % as my head was in 'percentage mode', so I thought a PR to allow "0%" might save someone else a few minutes of their time. This PR checks Number.isNaN on the output of the Number constructor which allows for 0 and any other legitimate number.

@gorhom
Copy link
Owner

gorhom commented Feb 14, 2021

thanks @richkeenan for submitting this pr 👏

@gorhom gorhom merged commit 2a62d26 into gorhom:master Feb 14, 2021
@richkeenan richkeenan deleted the allow-zero-percent branch February 14, 2021 22:54
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