-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Small follow-ups to the distraction free mode PR #45151
Conversation
@@ -38,6 +39,8 @@ function Header( { setEntitiesSavedStatesCallback, isDistractionFree } ) { | |||
isSaving: select( editPostStore ).isSavingMetaBoxes(), | |||
showIconLabels: | |||
select( editPostStore ).isFeatureActive( 'showIconLabels' ), | |||
isDistractionFree: |
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.
No need for prop passing from parent to children since we can access this here. The pro here is that the "Header" component becomes more reusable and if we remove the isDistractionFree selector from the parent it would result in a small perf optimization.
closeGeneralSidebar(); | ||
if ( ! isDistractionFree && !! blocks.length ) { | ||
selectBlock( blocks[ 0 ].clientId ); | ||
} |
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 think we can probably get rid of all of these if we just not render them in distraction free mode (remove the inserter, remove list view, remove the sidebar) that way if you switch back to regular mode, they restore to their previous state.
I didn't want to make that change here though.
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.
Yea commented to the original PR that this is the second option to this handler. It's a better way but it peppers the code with a lot of extra isDistractionFree
checks and my goal is to have the least impact initially.
|
||
useEffect( () => { | ||
setDistractionFree( isDistractionFree ); | ||
}, [ isDistractionFree ] ); |
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.
AFAIK, this was useless local state.
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.
These bits of code are surprising. I wouldn't have added it for no reason :D 🤷🏻 Probably didnt remove it on iteration X when it wasn't needed anymore 🙇🏻
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.
Yeah, sometimes it's hard to keep track of all the necessary/unnecessary bits as we iterate over feedback.
Size Change: +2 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
setIsInserterOpened( false ); | ||
setIsListViewOpened( false ); | ||
closeGeneralSidebar(); | ||
if ( ! isDistractionFree && !! blocks.length ) { |
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.
This is a bug fix where toggling distraction free would fail if the post was empty
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 code changes look good to me, and I couldn't spot any regressions.
Unrelated: When using the shortcut to switch the modes, if the focus is on one of the components that get unmounted, the shortcut stops working until I focus on a different element.
Yeah, I noticed this when working on my blog post on keyboard shortcuts. Basically, we only catch keyboard shortcuts if the focus is within the "shortcut provider". So we'd have two options here:
I'd start with the latter personally since the focus loss itself is probably an a11y issue. |
That explains the "focus on mount" in the code example 😄 I like the second option. Maybe we can focus on the first tabbable element in the header area, after switching the mode. P.S. The code editor also has a similar issue - #42145. |
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.
@youknowriad Do you have time to refactor this?
I am not super pleased that one menu option works differently then the other options in that list. Is there anyway to make the toolbar appear on hover/focus that way the options menu item can still receive focus without it looking super weird visually? Then once the user navigates away from it, it can disappear. That is how the toolbars work in full screen browser mode, not sure why it cannot happen here.
Other than that, LGTM.
Thanks.
To be honest I'm not entirely sure what you're talking about 😬 which toolbars/menu items... |
@youknowriad If you enable the distraction free mode from the options menu, the toolbar gets hidden and focus is shifted to the block list. This works differently then all the other options within the menu. For example, toggling full screen mode will check the box, but focus stays in the menu. It is an anti-pattern to have one item act differently in a menu of items that work exactly the same. Does that help? Thanks. |
@alexstine yes, that makes sense thank you and I agree. I'll see if I can improve that separately |
What?
Just addressing some of my comments on this PR #41740 (review) (more explanations inline)
Testing Instructions