-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add a dot before the parent block selector when there are unsaved changes in the Reusable block #1
Changes from 4 commits
a0ab538
da40570
1952b92
cd7bca8
0df63a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fill } from '@wordpress/components'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
function UnsavedChangesIndicator() { | ||
useEffect( () => { | ||
// add class to the parent selector to increase it's width | ||
const parentSelectorBtn = document.querySelector( | ||
'.block-editor-block-parent-selector' | ||
); | ||
parentSelectorBtn.classList.add( 'parent-block-has-changes' ); | ||
// add class to the contextual toolbar to move it to the right side | ||
const contextualToolBar = document.querySelector( | ||
'.block-editor-block-contextual-toolbar' | ||
); | ||
contextualToolBar.classList.add( 'parent-block-has-changes' ); | ||
|
||
return () => { | ||
// remove classes from the parent selector and contextual toolbar when component unmounts | ||
document | ||
.querySelector( '.block-editor-block-parent-selector' ) | ||
.classList.remove( 'parent-block-has-changes' ); | ||
document | ||
.querySelector( '.block-editor-block-contextual-toolbar' ) | ||
.classList.remove( 'parent-block-has-changes' ); | ||
}; | ||
}, [] ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not in favour of the modification of other parent elements when this renders. Is there a way to achieve the same result without that being required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unsaved changes indicator increases the width of the parent selector button. Since the parent selector button is positioned absolutely to the contextual toolbar, it leads to a state like this: That's why a new class I am not sure how to achieve this without affecting the contextual toolbar. If you have any suggestions, I will be more than happy to try them out 🙂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Interesting that this is positioned absolutely. That sounds like the core of the problem. Is there a way to style it so that it's an inline element? |
||
|
||
return ( | ||
<div className="parent-block-selector-unsaved-changes-indicator"></div> | ||
); | ||
} | ||
|
||
function ParentBlockSelectorUnsavedChangesIndicator() { | ||
return ( | ||
<> | ||
<Fill name="parent-block-selector-unsaved-changes-indicator"> | ||
<UnsavedChangesIndicator /> | ||
</Fill> | ||
</> | ||
); | ||
} | ||
|
||
export default ParentBlockSelectorUnsavedChangesIndicator; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fill } from '@wordpress/components'; | ||
|
||
function UnsavedChangesIndicator() { | ||
return <div className="block-unsaved-changes-indicator"></div>; | ||
} | ||
|
||
function SelectedBlockUnsavedChangesIndicator() { | ||
return ( | ||
<> | ||
<Fill name="block-unsaved-changes-indicator"> | ||
<UnsavedChangesIndicator /> | ||
</Fill> | ||
</> | ||
); | ||
} | ||
|
||
export default SelectedBlockUnsavedChangesIndicator; |
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 a slot renders nothing if there are no fills, so it should be fine to just render the slot without the surrounding
isReusable
logic.