-
Notifications
You must be signed in to change notification settings - Fork 6
Toggle the inserter option on by default #87
Conversation
Working here! |
@@ -1 +1,5 @@ | |||
export type { BaseSidebarProps as ToggleTypes } from '../SidebarPanels/types'; | |||
|
|||
export type AdditionalToggleTypes = { |
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.
It's not obvious to me why some are considered "Additional" and others are not. Is it possible to add a comment to clarify that here?
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 closed this PR, so these additional props are not being merged. But, to circle back — the base types are intended to be common between toggle components, while additional might only be used for one component and picked like this in the component:
export default function SomeComponent( {
someProp,
anotherProp,
}: BaseProps & Pick< AdditionalProps, 'extraProp' > ) {
...
}
It's a really useful pattern for SidebarPanels
, but it might honestly be over-abstraction here!
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.
Thanks for fixing this.
Does this fix it in your local?
(setting the default for 'toggle'
via register_post_meta()
)
diff --git a/wp-modules/editor/editor.php b/wp-modules/editor/editor.php
index abcdd7cd..52b6bd9a 100644
--- a/wp-modules/editor/editor.php
+++ b/wp-modules/editor/editor.php
@@ -79,6 +79,7 @@ function register_pattern_post_type() {
'show_in_rest' => true,
'single' => true,
'type' => 'boolean',
+ 'default' => true,
)
);
Great idea! It does correct the initial state of the toggle, but it flips to "off" automatically when I publish the pattern. |
Ahhh, OK. |
Hi @mike-day,
|
@kienstra it does work — I had something in my local that was throwing the result off. I am going to close this suggestion out since the issue is fixable with 1 new line (as opposed to my overcomplicated solution)! |
Thanks, Michael! |
Overcomplicated solutions happen. I probably do them more often than not. And you were fixing a bug in #78, so I really appreciate you working on it. |
Of course! I don't mind being wrong, especially if it means learning something new in process 😄 |
Currently on #78, the
inserter
toggle is toggled "off" when a new pattern is first opened in the editor (but before the post is published — i.e., before you actually save the pattern by hittingCreate Pattern
).But, if you leave the toggle "off", the value is automatically toggled "on" when the post is published.
To recreate:
Post Types
panelThis PR is just a suggestion for one way to get around this very minor issue. The toggle state will initially show as "on" (which I think is preferred), but you are free to toggle it "off" and have that value stay the same upon actually publishing the pattern.
How to test
The solution offered here is somewhat imperative — there might be a better way to do this!