Skip to content
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

AI Assistant: Remove autofocus on extended blocks while previewing #39216

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

AI Assistant: Remove autofocus on extended blocks while previewing
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type CoreEditorSelect = { getCurrentPostId: () => number };
// HOC to populate the block's edit component with the AI Assistant control inpuit and toolbar button.
const blockEditWithAiComponents = createHigherOrderComponent( BlockEdit => {
return props => {
const { clientId, isSelected, name: blockName } = props;
// Block props. isSelectionEnabled is used to determine if the block is in the editor or in the preview.
const { clientId, isSelected, name: blockName, isSelectionEnabled } = props;
// Ref to the control wrapper, its height and its ResizeObserver, for positioning adjustments.
const controlRef: React.MutableRefObject< HTMLDivElement | null > = useRef( null );
const controlHeight = useRef< number >( 0 );
Expand Down Expand Up @@ -390,13 +391,14 @@ const blockEditWithAiComponents = createHigherOrderComponent( BlockEdit => {

// Focus the input when the AI Control is displayed and set the ownerDocument.
useEffect( () => {
if ( inputRef.current ) {
// Do not focus the input if the block is a preview.
if ( inputRef.current && isSelectionEnabled ) {
// Save the block's ownerDocument to use it later, as the editor can be in an iframe.
ownerDocument.current = inputRef.current.ownerDocument;
// Focus the input when the AI Control is displayed.
focusInput();
}
}, [ showAiControl, focusInput ] );
}, [ showAiControl, focusInput, isSelectionEnabled ] );

// Adjusts the input position in the editor by increasing the block's bottom-padding
// and setting the control's margin-top, "wrapping" the input with the block.
Expand Down
Loading