@@ -3,18 +3,17 @@ import * as React from 'react';
33import { EmojiButtonSelector } from '../DomUtils/selectors' ;
44import {
55 useEmojiListRef ,
6- usePickerMainRef
6+ usePickerMainRef ,
77} from '../components/context/ElementRefContext' ;
88import {
99 useReactionsModeState ,
10- useVisibleCategoriesState
10+ useVisibleCategoriesState ,
11+ useEmojiSizeState ,
1112} from '../components/context/PickerContext' ;
1213
13- const EMOJI_SIZE_DEFAULT = 32 ;
14+ const EMOJI_SIZE_DEFAULT = 40 ;
1415
15- export function useCategoryHeight (
16- emojiCount : number
17- ) :
16+ export function useCategoryHeight ( emojiCount : number ) :
1817 | {
1918 categoryHeight : number ;
2019 emojisPerRow : number ;
@@ -26,6 +25,7 @@ export function useCategoryHeight(
2625 const PickerMainRef = usePickerMainRef ( ) ;
2726 const emojiSizeRef = React . useRef < number | undefined > ( ) ;
2827 const [ visibleCategories ] = useVisibleCategoriesState ( ) ;
28+ const [ emojiSizeFromContext ] = useEmojiSizeState ( ) ;
2929 const [ dimensions , setDimensions ] = React . useState < {
3030 categoryHeight : number ;
3131 emojisPerRow : number ;
@@ -38,12 +38,18 @@ export function useCategoryHeight(
3838 if ( ! listEl ) return ;
3939
4040 const emojiElement = listEl . querySelector (
41- EmojiButtonSelector
41+ EmojiButtonSelector ,
4242 ) as HTMLElement | null ;
4343
4444 const measured = emojiElement ?. clientHeight ;
45- const emojiSize = measured ?? emojiSizeRef . current ?? EMOJI_SIZE_DEFAULT ;
46- emojiSizeRef . current = emojiSize ;
45+ if ( measured ) {
46+ emojiSizeRef . current = measured ;
47+ }
48+ const emojiSize =
49+ emojiSizeFromContext ||
50+ measured ||
51+ emojiSizeRef . current ||
52+ EMOJI_SIZE_DEFAULT ;
4753 const pickerWidth = listEl . clientWidth ;
4854
4955 if ( pickerWidth === 0 || emojiSize === 0 ) return ;
@@ -53,7 +59,7 @@ export function useCategoryHeight(
5359 const categoryHeight = rowCount * emojiSize ;
5460
5561 setDimensions ( { categoryHeight, emojisPerRow, emojiSize } ) ;
56- } , [ EmojiListRef , emojiCount ] ) ;
62+ } , [ EmojiListRef , emojiCount , emojiSizeFromContext ] ) ;
5763
5864 // Recompute on data-count changes and when reactions mode toggles
5965 React . useEffect ( ( ) => {
@@ -62,7 +68,7 @@ export function useCategoryHeight(
6268 emojiCount ,
6369 isReactionsMode ,
6470 computeAndSetDimensions ,
65- visibleCategories . length
71+ visibleCategories . length ,
6672 ] ) ;
6773
6874 // Listen to transitionend on the picker root (where height transition occurs)
@@ -90,7 +96,7 @@ export function useCategoryHeight(
9096 } ;
9197
9298 rootEl . addEventListener ( 'transitionend' , handler , {
93- passive : true
99+ passive : true ,
94100 } ) ;
95101 return ( ) => {
96102 rootEl . removeEventListener ( 'transitionend' , handler ) ;
0 commit comments