-
Notifications
You must be signed in to change notification settings - Fork 157
fix(range-input): refine correctly when start is given #777
Conversation
src/components/RangeInput.vue
Outdated
@@ -11,7 +11,7 @@ | |||
> | |||
<form | |||
:class="suit('form')" | |||
@submit.prevent="refine({ min: minInput, max: maxInput })" | |||
@submit.prevent="refine({ min: minInput || values.min, max: maxInput || values.max })" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that this doesn't fully fix the bug. I think that it'll fix everything when a refresh is done, but the input will still behave strangely when you hit the browser's back button.
Let's say that you a range input:
- You put in min: 10, max: 100
- You hit Go
- You change min to 20
- You hit Go again
- You hit the back button on the browser (with the history router the page will not reload but the state of the search changes)
- You hit Go again
In this scenario, the min value will be reset to 60.
I believe that this will still happen with your fix. In that scenario minValue
would have been set to 60
and values.min
would have been set to 50
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if you added a watcher on value.min
& value.max
? In that watcher you could update minValue
& maxValue
every time value.min
& value.max
get updated by any source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this scenario, the min value will be reset to 60.
I believe that this will still happen with your fix. In that scenario minValue would have been set to 60 and values.min would have been set to 50.
Do you mean it will be reset to 20, while it should've stayed as 10, right?
You're right. I didn't think of that path. Thanks!
minInput is already a computed variable, not sure if that needs to be computed in the render again. Could you maybe start with writing a test of the behaviour which is failing now? |
I don't think @change="minInput = $event.currentTarget.value" data() {
return {
minInput: undefined,
maxInput: undefined,
};
}, It just stores the value from @change event handler. And the test case I added fails without my change. |
In a similar range input I made yesterday I used a watcher instead of |
Netlify fails due to time out, and e2e fails with connection errors. (I retried a couple of times). So I'm just merging this. ( |
Summary
This PR fixes a wrong refinement when
start
is given.fixes #776
Details
When
start
is given toais-range-input
and user clicks submit button without changing any input field, it broke.It's because the submit button was calling
Both
minInput
andmaxInput
are assigned at @change event of input field. But whenstart
is given, both of the input fields are already filled.So I've updated the
refine
call to take it into account.