Skip to content

Conversation

@dcalhoun
Copy link
Member

@dcalhoun dcalhoun commented Nov 20, 2025

What?

Ensure inline inserter's Browse all button opens the native block inserter.

It's worth noting the current outcome is not perfect. Namely, the quick inserter remains open after opening the native inserter. This occurs because the former relies upon losing focus for its dismissal. The native inserter does not change the WebView's focus state; thus, the quick inserter remains open.

Long term, I think the most ideal case is that we introduce a new filter hook to the Gutenberg project that allows replacing the inserter used throughout the UI. I.e., when tapping the quick inserter's inline button, it opens the native inserter directly rather than displaying the quick inserter. I captured this as a note in #106.

Why?

Fix CMM-973. The bug made inserting blocks into layout blocks difficult.

How?

  • Control the native inserter visibility via the existing isInserterOpen store state, ensuring the state is correct throughout the UI.
  • Memoize various callbacks to avoid unnecessary re-renders—this addresses some of Native Inserter: Implement block insertion #199 (comment).
  • Disable existing a11y logic that is unnecessary for the native inserter, as it manages the relevant a11y state itself (e.g., marking content outside the modal dialog inert).

Testing Instructions

  1. Open the inserter.
  2. Select Columns.
  3. Tap the inline inserter button.
  4. Tap Browse all.
  5. Select a block to insert.
  6. Verify the selected block is inserted.

Accessibility Testing Instructions

Navigate the testing steps. Verify content is correct marked inert when the native inserter is opened.

Screenshots or screencast

Simulator.Screen.Recording.-.iPhone.17.-.2025-11-20.at.09.17.25.mov

There is no need to communicate the inserter state via the bridge for
disabling native header navigation, as the native inserter already
obscures these UI elements.

There is no need to mark web content as inert, as the native insert
already marks the entire WebView inert.
If we do not respect the `isInserterOpened` state, various editor UI
elements cannot control the block inserter state. Align
`NativeBlockInserterButton`'s API with core's `Inserter`.
@dcalhoun dcalhoun added the [Type] Bug An existing feature does not function as intended label Nov 20, 2025
Comment on lines 64 to +69
useModalize( isBlockInspectorShown );

useModalDialogState( isInserterOpened, 'block-inserter' );
useModalDialogState(
isInserterOpened && ! enableNativeBlockInserter,
'block-inserter'
);
Copy link
Member Author

Choose a reason for hiding this comment

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

These marked content outside of the block inserter modal dialog "inert," and thus inaccessible by screen readers. This is unnecessary for the native inserter, as the native UI handles this itself. The WebView is inaccessible to screen readers when the native inserter is open.

Comment on lines +101 to +104
<NativeBlockInserterButton
open={ isInserterOpened }
onToggle={ setIsInserterOpened }
/>
Copy link
Member Author

Choose a reason for hiding this comment

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

This API matches the Gutenberg Inserter a few lines beneath this.

* @param {Array} items Array of media objects with IDs
* @return {boolean} True if insertion succeeded
*/
const insertMediaWithIds = ( items ) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to items to avoid duplicating the mediaArray name in the upper scope now that insertMediaWithIds is declared within insertMedia. It was relocated to simplify memoization.

Comment on lines +427 to +434
// Watch for controlled open state changes
useEffect( () => {
// Only trigger when transitioning from false to true
if ( open && ! prevOpen.current ) {
prepareAndShowInserter();
}
};
prevOpen.current = open;
}, [ open, prepareAndShowInserter ] );
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the crux of the change. Rather than onClick directly showing the inserter, the global isInserterOpen state now does so. This allows UI outside of this component's Button to open the native inserter.

debug( `Pattern "${ patternName }" not found` );
return false;
const prepareAndShowInserter = useCallback( () => {
const sections = preprocessBlockTypesForNativeInserter(
Copy link
Member Author

Choose a reason for hiding this comment

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

I used logging and the React Developer Tools to verify this complex logic is only run when opening the inserter.

@dcalhoun dcalhoun requested a review from kean November 20, 2025 14:52
@dcalhoun dcalhoun marked this pull request as ready for review November 20, 2025 14:52
Copy link
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

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

Thank you for address it. The code looks good.

As a potential future improvement, I would replacing the "quick inserter" itself with a native inserter (just show is as a small sheet the way it is shown now).

Screenshot 2025-11-20 at 2 47 12 PM

@dcalhoun
Copy link
Member Author

As a potential future improvement, I would replacing the "quick inserter" itself with a native inserter (just show is as a small sheet the way it is shown now).

Agreed. That is what I meant by the following in the PR description:

Long term, I think the most ideal case is that we introduce a new filter hook to the Gutenberg project that allows replacing the inserter used throughout the UI. I.e., when tapping the quick inserter's inline button, it opens the native inserter directly rather than displaying the quick inserter. I captured this as a note in #106.

@dcalhoun dcalhoun merged commit 414ffe7 into trunk Nov 20, 2025
11 checks passed
@dcalhoun dcalhoun deleted the fix/inline-inserter-opens-native-inserter branch November 20, 2025 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants