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

Fixed Range Control Reset Button #14919

Closed
wants to merge 5 commits into from

Conversation

rebeccaj1211
Copy link

@rebeccaj1211 rebeccaj1211 commented Apr 11, 2019

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 -1 whatever 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:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@rebeccaj1211 rebeccaj1211 changed the title fixed issue #14166 Fixed Range Control Reset Button Apr 11, 2019
@Soean Soean added the [Block] RSS Affects the RSS Block - used to display entries from an RSS/Atom feed label Apr 11, 2019
@gziolo gziolo added [Feature] UI Components Impacts or related to the UI component system [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). labels Apr 11, 2019
packages/components/src/range-control/index.js Outdated Show resolved Hide resolved
packages/block-library/src/rss/edit.js Outdated Show resolved Hide resolved
packages/components/src/range-control/index.js Outdated Show resolved Hide resolved
@gziolo gziolo added Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code Needs Accessibility Feedback Need input from accessibility labels Apr 19, 2019
@@ -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 }
Copy link
Member

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

Copy link
Author

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

Copy link
Member

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?

Copy link
Member

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.
image
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.

Copy link
Member

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 ) ?
Copy link
Member

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.

Suggested change
const initialInputValue = ! ( initialValue && min <= initialValue && max >= initialValue ) ?
const initialInputValue = ( initialPosition && initialPosition >= min && initialPosition <= max ) ? parseFloat( initialPosition ) : undefined;

Copy link
Author

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.

@gziolo
Copy link
Member

gziolo commented Apr 26, 2019

It tests well. I left 2 additional comments where at least the one about reusing the existing initialPosition prop has to be addressed. I also flagged this PR for accessibility review.

@afercia afercia removed the Needs Accessibility Feedback Need input from accessibility label May 9, 2019
@afercia
Copy link
Contributor

afercia commented May 9, 2019

Originally, the range control bar would move to original position when the reset button was pressed but the number stayed the same.

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 considerations

1
I've noticed the "Reset" button gets disabled with a disabled HTML attribute. This is a pre-existing issue but worth reminding again we can't simply disable a UI control while it has keyboard focus, because that will produce a focus loss. For other similar cases we're no-oping the control and using aria-disabled instead. Will open a separate issue.

2
Seems to me in the RSS component there are other range controls with a default value (and maybe other ones in other components?). For example, when enabling "Display Excerpt":

excerpt

or when switching to the Grid layout:

columns in grid layout

Should these range controls have a reset button as well?

3
Styling: the "Reset" button needs some styling. See in the screenshot below. On the left: normal state, on the right: focused:

Screenshot 2019-05-09 at 09 22 58

Compared with the reset button in the font size picker:

Screenshot 2019-05-09 at 09 24 31

Seems to me this button needs the following props to start with:

className="components-range-control__clear"
isSmall
isDefault

then it will need some spacing on the left.

Will leave other considerations to @gziolo 🙂

@gziolo
Copy link
Member

gziolo commented May 16, 2019

Styling: the "Reset" button needs some styling. See in the screenshot below. On the left: normal state, on the right: focused:

Screenshot 2019-05-09 at 09 22 58

Compared with the reset button in the font size picker:

Screenshot 2019-05-09 at 09 24 31

Seems to me this button needs the following props to start with:

className="components-range-control__clear"
isSmall
isDefault

@mapk - can we get some design help here?

@gziolo gziolo added the Needs Design Feedback Needs general design feedback. label May 16, 2019
@mapk
Copy link
Contributor

mapk commented May 18, 2019

can we get some design help here?

Thanks for the ping! Definitely. Let's go with a Reset button like the two examples below. This seems to be the emerging pattern for Gutenberg right now.

Columns reset

column-reset

Font reset

font-reset

@gziolo gziolo removed the Needs Design Feedback Needs general design feedback. label May 21, 2019
@gziolo gziolo added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jun 3, 2019
Base automatically changed from master to trunk March 1, 2021 15:42
@Mamaduka
Copy link
Member

Mamaduka commented Sep 7, 2021

Thanks so much for working on this PR. It looks like the RangeControls component got fully revamped, and that addressed the same issue.

I'm going to close this out as a result.

@Mamaduka Mamaduka closed this Sep 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] RSS Affects the RSS Block - used to display entries from an RSS/Atom feed [Feature] UI Components Impacts or related to the UI component system First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants