Skip to content

Commit d0d9e1e

Browse files
committed
fix: make scrolling to current font pair independent from current view
1 parent a81ea2c commit d0d9e1e

File tree

1 file changed

+7
-3
lines changed
  • src/plugins/global-settings/typography

1 file changed

+7
-3
lines changed

src/plugins/global-settings/typography/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,15 @@ addFilter( 'stackable.global-settings.inspector', 'stackable/global-typography',
9696
doAction( 'stackable.global-settings.typography.update-trigger', typographySettings, applySettingsTo )
9797
}, [ JSON.stringify( typographySettings ), applySettingsTo ] )
9898

99+
// Scroll to the selected font pair when Global Typography tab is toggled
99100
useEffect( () => {
100-
if ( fontPairContainerRef.current ) {
101-
const selectedElement = fontPairContainerRef.current.querySelector( '.ugb-global-settings-font-pair__selected' )
101+
const container = fontPairContainerRef?.current
102+
if ( container ) {
103+
const selectedElement = container.querySelector( '.ugb-global-settings-font-pair__selected' )
102104
if ( selectedElement ) {
103-
selectedElement.scrollIntoView( { behavior: 'instant', block: 'center' } )
105+
const containerRect = container.getBoundingClientRect()
106+
const selectedRect = selectedElement.getBoundingClientRect()
107+
container.scrollTop = selectedRect.top + ( selectedRect.height / 2 ) - containerRect.top - ( containerRect.height / 2 )
104108
}
105109
}
106110
}, [ isPanelOpen ] )

0 commit comments

Comments
 (0)