Skip to content

Commit

Permalink
AI Assistant bar: fix positioning on mobile (#34476)
Browse files Browse the repository at this point in the history
* wrap assistant bar to control positioning

* always make sure the assistant bar is placed AFTER the toolbar

* add changelog entry
  • Loading branch information
CGastrell committed Dec 18, 2023
1 parent 4630a95 commit f3fb0a4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: enhancement

AI Assistant bar: fix issues introduced by latest block sticky positioning, make sure assistant bar is always AFTER main toolbar
Original file line number Diff line number Diff line change
Expand Up @@ -230,42 +230,44 @@ export default function AiAssistantBar( {

// Assistant bar component.
const AiAssistantBarComponent = (
<KeyboardShortcuts
bindGlobal
shortcuts={ {
esc: () => {
if ( [ 'requesting', 'suggesting' ].includes( requestingState ) ) {
handleStopSuggestion();
}
},
} }
>
<div
ref={ wrapperRef }
className={ classNames( 'jetpack-ai-assistant__bar', {
[ className ]: className,
'is-fixed': isAssistantBarFixed,
'is-mobile-mode': isMobileMode,
} ) }
tabIndex={ -1 }
<div className="jetpack-ai-assistant__bar-wrapper">
<KeyboardShortcuts
bindGlobal
shortcuts={ {
esc: () => {
if ( [ 'requesting', 'suggesting' ].includes( requestingState ) ) {
handleStopSuggestion();
}
},
} }
>
{ siteRequireUpgrade && <UpgradePrompt /> }
{ ! connected && <ConnectPrompt /> }
<AIControl
ref={ inputRef }
disabled={ siteRequireUpgrade || ! connected }
value={ inputValue }
placeholder={ isLoading ? loadingPlaceholder : placeholder }
onChange={ setInputValue }
onSend={ handleSend }
onStop={ handleStopSuggestion }
state={ requestingState }
isTransparent={ siteRequireUpgrade || ! connected }
showButtonLabels={ ! isMobileMode }
showGuideLine={ showGuideLine }
/>
</div>
</KeyboardShortcuts>
<div
ref={ wrapperRef }
className={ classNames( 'jetpack-ai-assistant__bar', {
[ className ]: className,
'is-fixed': isAssistantBarFixed,
'is-mobile-mode': isMobileMode,
} ) }
tabIndex={ -1 }
>
{ siteRequireUpgrade && <UpgradePrompt /> }
{ ! connected && <ConnectPrompt /> }
<AIControl
ref={ inputRef }
disabled={ siteRequireUpgrade || ! connected }
value={ inputValue }
placeholder={ isLoading ? loadingPlaceholder : placeholder }
onChange={ setInputValue }
onSend={ handleSend }
onStop={ handleStopSuggestion }
state={ requestingState }
isTransparent={ siteRequireUpgrade || ! connected }
showButtonLabels={ ! isMobileMode }
showGuideLine={ showGuideLine }
/>
</div>
</KeyboardShortcuts>
</div>
);

// Check if the Assistant bar should be rendered in the Assistant anchor (fixed mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
&:not(.is-fixed) {
position: relative;
z-index: 30;

margin-top: 10px;
background-color: white;
}

&.is-fixed {
border-bottom: 1px solid #e0e0e0;
.jetpack-components-ai-control__container-wrapper {
position: relative;
padding-bottom: 0;
}

.jetpack-components-ai-control__container {
border-radius: 0;
Expand All @@ -29,4 +30,14 @@
display: block;
position: sticky;
z-index: 31;

.jetpack-ai-assistant__bar-wrapper {
position: relative;
}
}

.jetpack-ai-assistant__bar-wrapper {
position: sticky;
bottom: 0;
z-index: 30;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export default function AiAssistantToolbarButton( {
let slot = toolbar.parentElement?.querySelector(
`.${ AI_ASSISTANT_BAR_SLOT_CLASS }`
) as HTMLElement;

if ( slot ) {
// always move the slot right after the toolbar.
toolbar.after( slot );
return setAnchor( slot );
}

Expand All @@ -81,11 +84,11 @@ export default function AiAssistantToolbarButton( {
slot.setAttribute( 'aria-label', __( 'AI Assistant', 'jetpack' ) );
slot.setAttribute( 'aria-orientation', 'horizontal' );
slot.className = AI_ASSISTANT_BAR_SLOT_CLASS;
toolbar.after( slot );

// Set the top position based on the toolbar height.
const toolbarHeight = toolbar.offsetHeight;
slot.style.top = `${ toolbarHeight }px`;
toolbar.after( slot );

// Set the anchor where the Assistant Bar will be rendered.
setAnchor( slot );
Expand Down

0 comments on commit f3fb0a4

Please sign in to comment.