-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fixed Range Control Reset Button #14919
Conversation
@@ -119,6 +120,8 @@ class RSSEdit extends Component { | |||
onChange={ ( value ) => setAttributes( { itemsToShow: value } ) } | |||
min={ DEFAULT_MIN_ITEMS } | |||
max={ DEFAULT_MAX_ITEMS } | |||
allowReset={ true } | |||
initialValue={ this.state.initialItemsToShow } |
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 noticed that there is already initialPosition
prop which plays exactly the same role. We should use it instead. See:
https://github.com/WordPress/gutenberg/tree/c2c112846126e786939c2525a2c802d6016a2c82/packages/components/src/range-control#initialposition
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.
The initialPosistion prop updates each time the slider button is changed. If I simply reset to initialPosition, nothing would change. This is why I created the initialValue
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.
The initialPosistion prop updates each time the slider button is changed. If I simply reset to initialPosition, nothing would change. This is why I created the initialValue
@jorgefilipecosta - I see that you have added initialPosition
in #6088. Can you clarify its intended behavior?
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.
The initialPosition property allows the slider circle to appear as if a given value was select, when in fact the value is undefined.
This was the functionality that allowed the font size picker to appear in a position that makes sense instead of appearing in the middle when the font size is unset.
The font size picker was meanwhile redesigned and core is not using this feature anymore, but I guess we need to keep it in order to be back-compatible with existing plugins.
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.
Interesting, this means it's something different and its description should be updated to better reflect it. I remember what was the case, we wanted to show the current font size inherited from the CSS used by the theme author.
...props | ||
} ) { | ||
const id = `inspector-range-control-${ instanceId }`; | ||
const currentInputValue = currentInput === null ? value : currentInput; | ||
const initialInputValue = ! ( initialValue && min <= initialValue && max >= initialValue ) ? |
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.
It would read easier if the check would start with a positive condition.
const initialInputValue = ! ( initialValue && min <= initialValue && max >= initialValue ) ? | |
const initialInputValue = ( initialPosition && initialPosition >= min && initialPosition <= max ) ? parseFloat( initialPosition ) : undefined; |
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.
So I used initialValue instead of initialPosition for reason above.
It tests well. I left 2 additional comments where at least the one about reusing the existing |
Right, seems to me this is a bug 🙂I'd be all for fixing it, thanks for your PR! Worth noting there are other usability and accessibility concerns regarding the Range Control so I've edited the "Fixes" in this PR original description and changed it to "See". In fact, this PR is a welcomed improvements but can't close #14166. Other considerations1 2 or when switching to the Grid layout: Should these range controls have a reset button as well? 3 Compared with the reset button in the font size picker: Seems to me this button needs the following props to start with:
then it will need some spacing on the left. Will leave other considerations to @gziolo 🙂 |
@mapk - can we get some design help here? |
Thanks so much for working on this PR. It looks like the I'm going to close this out as a result. |
Description
Originally, the range control bar would move to original position when the reset button was pressed but the number stayed the same.
Now, when you press the reset button the position moves to the original position (if specified) and default number (added new property). For the current blocks that utilize this, they do not have this new property so it will default to
-1whatever default is set in attributes.The default value for RSS is 5, so I manually added that property for testing purposes but also so it's one less block that needs to be modified to use the default value.The default value for RSS is 5 (which was passed in through its attributes). However, this attribute would change each time the block was rendered so we had to save it in state.See #14166
How has this been tested?
I manually tested it and it passes all unit test cases.
Screenshots
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: