Skip to content

Hide Preview menu on small viewports and fix regression for FSE preview - #24537

Merged
ntsekouras merged 2 commits into
masterfrom
fix/hide-preview-menu-dropdown-on-mobile
Aug 17, 2020
Merged

ntsekouras merged 2 commits into
masterfrom
fix/hide-preview-menu-dropdown-on-mobile

Conversation

@ntsekouras

Copy link
Copy Markdown
Contributor

Description

Resolves: #24385

Also fixes a small regression from this PR: #24487, that hid the Preview component in FSE.

@ntsekouras ntsekouras added [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release CSS Styling Related to editor and front end styles, CSS-specific issues. labels Aug 13, 2020
@ntsekouras ntsekouras self-assigned this Aug 13, 2020
@github-actions

github-actions Bot commented Aug 13, 2020 •

Copy link
Copy Markdown

Size Change: +34 B (0%)

Total Size: 1.16 MB

Filename Size Change
build/block-editor/index.js 125 kB +22 B (0%)
build/block-editor/style-rtl.css 10.7 kB +25 B (0%)
build/block-editor/style.css 10.7 kB +25 B (0%)
build/edit-post/style-rtl.css 5.62 kB -19 B (0%)
build/edit-post/style.css 5.61 kB -19 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.44 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 7.97 kB 0 B
build/block-directory/style-rtl.css 953 B 0 B
build/block-directory/style.css 952 B 0 B
build/block-library/editor-rtl.css 8.36 kB 0 B
build/block-library/editor.css 8.36 kB 0 B
build/block-library/index.js 132 kB 0 B
build/block-library/style-rtl.css 7.49 kB 0 B
build/block-library/style.css 7.49 kB 0 B
build/block-library/theme-rtl.css 729 B 0 B
build/block-library/theme.css 730 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.4 kB 0 B
build/components/index.js 200 kB 0 B
build/components/style-rtl.css 15.7 kB 0 B
build/components/style.css 15.7 kB 0 B
build/compose/index.js 9.68 kB 0 B
build/core-data/index.js 11.8 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.45 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.23 kB 0 B
build/edit-navigation/index.js 10.9 kB 0 B
build/edit-navigation/style-rtl.css 1.08 kB 0 B
build/edit-navigation/style.css 1.08 kB 0 B
build/edit-post/index.js 304 kB 0 B
build/edit-site/index.js 17 kB 0 B
build/edit-site/style-rtl.css 3.06 kB 0 B
build/edit-site/style.css 3.06 kB 0 B
build/edit-widgets/index.js 11.7 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 45.3 kB 0 B
build/editor/style-rtl.css 3.8 kB 0 B
build/editor/style.css 3.79 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.11 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.33 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.41 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.71 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@jasmussen

Copy link
Copy Markdown
Contributor

Nice.

Before:

fix

After:

after

From this testing shown above, though, you can see that the preview dropdown is only hidden when the mobile breakpoint is invoked. I wonder if it should be closed? I know that's a tougher thing to fix, and this improves the situation. But when the preview is open, focus is captured there, when it then gets hidden you can set focus elsewhere, and focus is no longer trapped inside when you go back.

@ntsekouras

Copy link
Copy Markdown
Contributor Author

But when the preview is open, focus is captured there, when it then gets hidden you can set focus elsewhere, and focus is no longer trapped inside when you go back.

Good point @jasmussen! I'm investigating about a React based solution :)

@ntsekouras

Copy link
Copy Markdown
Contributor Author

@jasmussen when you have time you cat take this again for a spin? :)

@jasmussen

Copy link
Copy Markdown
Contributor

This is working well for me!

Focus is put on the body element when the menu is open and you resize the viewport. I'm not sure what the best practice for responsive design and focus management on disappearing elements is. Seems like it would be nice to set focus on the preview button, but that might also be overdoing it? Happy to defer to someone else. But as is, this seems to work better than it did a moment ago, and is an overall net improvement!

@ntsekouras ntsekouras added the Needs Accessibility Feedback Need input from accessibility label Aug 13, 2020

@enriquesanchez enriquesanchez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just tested and worked as expected:

2020-08-13 18-01-44 2020-08-13 18_02_42

Seems like it would be nice to set focus on the preview button, but that might also be overdoing it?

Agreed, I think focus should be retained on the Preview button, otherwise, it's disorienting.

@ntsekouras

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing @enriquesanchez !

Agreed, I think focus should be retained on the Preview button, otherwise, it's disorienting.

Open the Preview menu -> change orientation -> change orientation immediately back:

is just one scenario of the many. In most cases the user might keep on doing things, and probably try to click the same button again, which now is just a link.

Should we keep track of this change ( orientation ) and then track any new focus and if no focus occurs and orientation changes again to focus the Preview button? Also this is implemented technically with just width check and no change orientation event, so I'm not really sure how easy/effective would be to track..

-cc @mcsf @youknowriad

@jasmussen

Copy link
Copy Markdown
Contributor

I think it's an open question. Focus lands on body when you size down the browser and focus is removed from the popover. That lets you tab through the document again. So I don't know that you could call that focus being lost — it's very literally an edgecase where you resize a window when a popover is open and has focus.

While it might be be luxurious to handle focus in the way outlined, it might also be shooting birds with cannons. Unless there's a use case I'm missing, in order to invoke this use case, you have to first click the preview dialog on a big window. Then you have to actively click outside the editing canvas to resize the window to close the popover. While resizing a window does not remove focus inside an active webpage, it does involve clicking elsewhere and then clicking back, at which point there's a great chance you'll set focus in a new place, or at least remove focus from where it was.

My question is legitimate: is there a best practice for handling focus in responsive situations where an element gets removed from the DOM?

Microsoft Word is not the best parallel or example or even representative necessarily of a best practice. But just as a quick test: no, they don't do anything to handle focus in responsive cases:

word online

@enriquesanchez

Copy link
Copy Markdown
Contributor

Definitively an edge case, but I see this being a possible occurrence for someone using a hand-held device, like a phone, and also using a screen reader.

In that scenario, the user doesn't need to click elsewhere (in which case I agree the focus has been intentionally moved by the user) but only tilt or rotate their device. The feeling of disorientation would probably be worse if you're using a screen-reader and don't perceive the layout changes on screen due to the device's orientation change. All of the sudden you find your focus somewhere else without knowing why.

@ntsekouras

Copy link
Copy Markdown
Contributor Author

I don't believe there is a focus tracking system right now and to build one would be definitely a bigger job. I'm also a bit concerned about the complexity and if it would be better to find another way to handle the specific case of Preview menu, as no other similar cases like these come in my mind now and that would mean building a system only for this case. As @jasmussen summarises my concern:

While it might be be luxurious to handle focus in the way outlined, it might also be shooting birds with cannons.

I believe this could be discussed and addressed in a follow up PR, taking into account the current behaviour in master. Would this PR be at least a step forward or would make things worse? :)

Do you think this is a blocker for now @enriquesanchez? If yes, I should create a separate PR to fix a small regression that hides Preview menu in FSE, as I had it in here because I thought it would have no other concerns ( focus ).

@enriquesanchez

Copy link
Copy Markdown
Contributor

@ntsekouras I don't think it's a blocker and this is definitively an improvement that addresses the initial issue.

@ntsekouras
ntsekouras merged commit 06204b5 into master Aug 17, 2020
@ntsekouras
ntsekouras deleted the fix/hide-preview-menu-dropdown-on-mobile branch August 17, 2020 15:57
@github-actions github-actions Bot added this to the Gutenberg 8.8 milestone Aug 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CSS Styling Related to editor and front end styles, CSS-specific issues. Needs Accessibility Feedback Need input from accessibility [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preview menu: dropdown still available on mobile when changing device orientation

3 participants