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

RangeControl: Fix Reset and initialPosition #20247

Merged
merged 7 commits into from
Mar 9, 2020

Conversation

ItsJonQ
Copy link

@ItsJonQ ItsJonQ commented Feb 14, 2020

Description

This update is a followup to the recently updated RangeControl.

It resolves how values are outputted based on initialPosition, external/internal value, and Reset handling.

These are some scenarios this update resolves:

  • If there is no value, initialPosition, or currentInput, the slider should appear to be centered, with nothing showing in the NumberInput.

  • If there is an initialPosition and value defined, it should use value.

  • If a reset action occurs, it will default to using null value. However, if the parent component uses an alternative value, it will resolve to that instead.

How has this been tested?

  • Locally in Storybook (+knobs)
  • Wrote additional unit tests for the scenarios described above
  • Local development

Screenshots

Screen Capture on 2020-02-14 at 13-48-09

The above GIF showcases the initial render with no defined values, resulting in a slider that's appears 50% filled. After adjusting the values, clicking reset will shift it back to 50%.

Types of changes

Takes care of some of the issues describe:
#20236 (comment)

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.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

Thank you! 🙏

Comment on lines -4943 to +4889
.emotion-10 {
.emotion-18 {
Copy link
Member

Choose a reason for hiding this comment

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

Should we worry about how unstable these incrementing IDs are?

Copy link
Author

Choose a reason for hiding this comment

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

Something to be observe I think 👍
To be honest, I've never used Storybook Snapshots together with Emotion prior to this project.

These updates snapshot changes make sense, as a push I made directly affect the styles that are computed/generated, which I suppose, affects the number of IDs that need to be incremented.

@@ -48,6 +48,7 @@ const BaseRangeControl = forwardRef(
allowReset = false,
beforeIcon,
className,
currentInput,
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused. What is this prop? Why is it needed? How do we document it?

Copy link
Author

Choose a reason for hiding this comment

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

To be honest... I'm not sure. But it was from the original RangeControl before the refactor 🙃 . I brought it back to preserve the value logic it had

Copy link
Member

Choose a reason for hiding this comment

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

It's nor used or documented in Gutenberg so maybe we can pretend it was never there and forget about it?

@github-actions
Copy link

github-actions bot commented Feb 20, 2020

Size Change: +4.49 kB (0%)

Total Size: 866 kB

Filename Size Change
build/annotations/index.js 3.43 kB -3 B (0%)
build/block-editor/index.js 104 kB +580 B (0%)
build/block-editor/style-rtl.css 10.5 kB +710 B (6%) 🔍
build/block-editor/style.css 10.5 kB +715 B (6%) 🔍
build/block-library/editor-rtl.css 7.66 kB -13 B (0%)
build/block-library/editor.css 7.66 kB -8 B (0%)
build/block-library/index.js 116 kB +1.98 kB (1%)
build/block-library/style-rtl.css 7.49 kB +16 B (0%)
build/block-library/style.css 7.5 kB +16 B (0%)
build/blocks/index.js 57.6 kB +1 B
build/components/index.js 191 kB +946 B (0%)
build/components/style-rtl.css 15.5 kB -529 B (3%)
build/components/style.css 15.5 kB -535 B (3%)
build/compose/index.js 5.76 kB -1 B
build/core-data/index.js 10.5 kB +5 B (0%)
build/data-controls/index.js 1.03 kB -5 B (0%)
build/data/index.js 8.22 kB -5 B (0%)
build/date/index.js 5.37 kB +3 B (0%)
build/deprecated/index.js 772 B +1 B
build/dom-ready/index.js 568 B -1 B
build/dom/index.js 3.06 kB -1 B
build/edit-post/index.js 90.9 kB +230 B (0%)
build/edit-post/style-rtl.css 8.59 kB -102 B (1%)
build/edit-post/style.css 8.58 kB -94 B (1%)
build/edit-site/index.js 4.63 kB +1.92 kB (41%) 🚨
build/edit-site/style-rtl.css 2.51 kB -108 B (4%)
build/edit-site/style.css 2.51 kB -108 B (4%)
build/edit-widgets/index.js 4.42 kB +68 B (1%)
build/edit-widgets/style-rtl.css 2.59 kB -208 B (8%)
build/edit-widgets/style.css 2.58 kB -207 B (8%)
build/editor/editor-styles-rtl.css 325 B -2 B (0%)
build/editor/editor-styles.css 327 B -1 B
build/editor/index.js 44.6 kB -519 B (1%)
build/editor/style-rtl.css 4.01 kB -115 B (2%)
build/editor/style.css 4 kB -111 B (2%)
build/element/index.js 4.45 kB +1 B
build/format-library/index.js 7.6 kB +1 B
build/format-library/style-rtl.css 502 B +2 B (0%)
build/format-library/style.css 502 B +1 B
build/hooks/index.js 1.92 kB -1 B
build/html-entities/index.js 622 B +1 B
build/i18n/index.js 3.48 kB +37 B (1%)
build/is-shallow-equal/index.js 710 B -1 B
build/keyboard-shortcuts/index.js 2.3 kB +3 B (0%)
build/list-reusable-blocks/style-rtl.css 226 B +11 B (4%)
build/list-reusable-blocks/style.css 226 B +10 B (4%)
build/media-utils/index.js 4.85 kB +5 B (0%)
build/notices/index.js 1.57 kB +2 B (0%)
build/nux/index.js 3.02 kB +6 B (0%)
build/plugins/index.js 2.54 kB +1 B
build/primitives/index.js 1.49 kB -1 B
build/priority-queue/index.js 780 B -98 B (12%) 👏
build/rich-text/index.js 14.3 kB -5 B (0%)
build/server-side-render/index.js 2.54 kB -2 B (0%)
build/token-list/index.js 1.27 kB -1 B
build/url/index.js 4 kB +1 B
build/viewport/index.js 1.61 kB +2 B (0%)
build/warning/index.js 1.14 kB +1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.01 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.58 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.02 kB 0 B
build/block-directory/style-rtl.css 760 B 0 B
build/block-directory/style.css 760 B 0 B
build/block-library/theme-rtl.css 669 B 0 B
build/block-library/theme.css 671 B 0 B
build/block-serialization-default-parser/index.js 1.65 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/escape-html/index.js 733 B 0 B
build/keycodes/index.js 1.68 kB 0 B
build/list-reusable-blocks/index.js 2.99 kB 0 B
build/nux/style-rtl.css 616 B 0 B
build/nux/style.css 613 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/wordcount/index.js 1.18 kB 0 B

compressed-size-action

@ItsJonQ
Copy link
Author

ItsJonQ commented Feb 20, 2020

Merged the latest!

@gziolo
Copy link
Member

gziolo commented Feb 24, 2020

There is still one concern to discuss. When the tooltip shows up and I move the mouse up it prevents me from clicking the previous range control. Would it be possible to hide the tooltip as soon as you no longer hover the range control circle?

Screen Shot 2020-02-24 at 14 59 37

Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

Looks good to me.

There is this issue with the tooltips I mentioned in my previous comment that should be improved but it isn't a blocker in my opinion. It's a minor inconvenience.

You also should decide what to do about currentInput that seems unnecessary.


useEffect( () => {
if ( valueRef.current !== valueProp ) {
setClampValue( valueProp );
valueRef.current = valueProp;
}
}, [ valueProp, setClampValue ] );
}, [ valueRef, valueProp, setValue ] );
Copy link
Member

Choose a reason for hiding this comment

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

I can't immediately recall where the conversation, but I have some recollection of discussing that it may be a concern to include a useRef variable as a dependency of another hook?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, found it here: #20219 (comment)

Jon Q added 2 commits February 27, 2020 10:13
@ItsJonQ
Copy link
Author

ItsJonQ commented Mar 9, 2020

Thanks for the reviews! Merging this up!

@ItsJonQ ItsJonQ merged commit 6066186 into master Mar 9, 2020
@ItsJonQ ItsJonQ deleted the fix/range-control-initial-and-reset branch March 9, 2020 21:45
@github-actions github-actions bot added this to the Gutenberg 7.8 milestone Mar 9, 2020
@youknowriad youknowriad removed this from the Gutenberg 7.8 milestone Mar 12, 2020
@youknowriad youknowriad added this to the Gutenberg 7.7 milestone Mar 12, 2020
youknowriad pushed a commit that referenced this pull request Mar 12, 2020
* RangeControl: Fix reset and initialPosition logic

* Add tests for desired initialPosition, value, and reset scenarios

* Update storybook snapshots

* Fix null value fill for marks

* Remove unnecessary ref dependency in useEffect hook

* Adjust Range x Tooltip interactions

So that hovering on a tooltip no longer keeps it open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants