Skip to content

Commit

Permalink
FontSizePicker: truncate option name based on viewport size
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Dec 25, 2024
1 parent 75ef79e commit e11978c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
FontSizePickerSelectOption,
} from './types';
import { getCommonSizeUnit, isSimpleCssValue } from './utils';
import { useViewportMatch } from '@wordpress/compose';

const DEFAULT_OPTION: FontSizePickerSelectOption = {
key: 'default',
Expand Down Expand Up @@ -66,6 +67,11 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
? options.find( ( option ) => option.value === value ) ?? CUSTOM_OPTION
: DEFAULT_OPTION;

const isMobileViewport = useViewportMatch( 'medium', '<' );
const truncate = ( str: string, maxLength: number ) => {
return str.length > maxLength ? str.slice( 0, maxLength ) + '…' : str;
};

return (
<CustomSelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
Expand All @@ -79,7 +85,13 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
selectedOption.name
) }
options={ options }
value={ selectedOption }
value={ {
...selectedOption,
name: truncate(
selectedOption.name,
isMobileViewport ? 45 : 30
),
} }
showSelectedHint
onChange={ ( {
selectedItem,
Expand Down

0 comments on commit e11978c

Please sign in to comment.