-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Improvements to use-focus-first-element and utils (dom) #39461
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
Changes from 1 commit
fac5b03
33bdfc5
21b47b1
e454097
cbd79e6
4ffec9c
14fd4ad
42ddba7
ee84ab2
cd9df4a
bb7a855
fc14a9b
c5dae59
6ed767d
007d826
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…provements. Type improvements. Add back the ability to skip block specific inserter. Add custom option to toggle this ability.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| const BLOCK_SELECTOR = '.block-editor-block-list__block'; | ||
| const APPENDER_SELECTOR = '.block-list-appender'; | ||
| //const BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender'; | ||
| const BLOCK_APPENDER_CLASS = '.block-editor-button-block-appender'; | ||
|
|
||
| /** | ||
| * Returns true if two elements are contained within the same block. | ||
|
|
@@ -18,16 +18,28 @@ export function isInSameBlock( a, b ) { | |
| * Returns true if an element is considered part of the block and not its inner | ||
| * blocks or appender. | ||
| * | ||
| * @param {Element} blockElement Block container element. | ||
| * @param {Element} element Element. | ||
| * @param {Element} blockElement Block container element. | ||
| * @param {Element} element Element. | ||
| * @param {{ skipBlockInserter: boolean }} options Custom options to set. | ||
| * | ||
| * @return {boolean} Whether an element is considered part of the block and not | ||
| * its inner blocks or appender. | ||
| */ | ||
| export function isInsideRootBlock( blockElement, element ) { | ||
| export function isInsideRootBlock( | ||
| blockElement, | ||
| element, | ||
| options = { skipBlockInserter: false } | ||
| ) { | ||
|
||
| const parentBlock = element.closest( | ||
| [ BLOCK_SELECTOR, APPENDER_SELECTOR ].join( ',' ) | ||
| ); | ||
| // Skip inserter for blocks such as group block. | ||
| if ( | ||
| options.skipBlockInserter && | ||
| parentBlock?.classList.contains( BLOCK_APPENDER_CLASS ) | ||
| ) { | ||
| return false; | ||
| } | ||
| return parentBlock === blockElement; | ||
| } | ||
|
|
||
|
|
||
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 am also fairly certain this returns true/false.