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

Fixes the FontSizePicker Custom option #18842

Merged
merged 5 commits into from Dec 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/components/src/font-size-picker/index.js
Expand Up @@ -21,15 +21,18 @@ function getSelectValueFromFontSize( fontSizes, value ) {
return 'normal';
}

function getSelectOptions( optionsArray ) {
return [
...optionsArray.map( ( option ) => ( {
key: option.slug,
name: option.name,
style: { fontSize: option.size },
} ) ),
{ key: 'custom', name: __( 'Custom' ) },
];
function getSelectOptions( optionsArray, disableCustomFontSizes ) {
if ( ! disableCustomFontSizes ) {
optionsArray = [
ZebulanStanphill marked this conversation as resolved.
Show resolved Hide resolved
...optionsArray,
{ slug: 'custom', name: __( 'Custom' ) },
];
}
return optionsArray.map( ( option ) => ( {
key: option.slug,
name: option.name,
style: { fontSize: option.size },
} ) );
}

function FontSizePicker( {
Expand Down Expand Up @@ -62,7 +65,12 @@ function FontSizePicker( {
onChange( selectedItem.style && selectedItem.style.fontSize );
};

const items = getSelectOptions( fontSizes );
const onSliderChangeValue = ( sliderValue ) => {
onChange( sliderValue );
setCurrentSelectValue( getSelectValueFromFontSize( fontSizes, sliderValue ) );
};

const items = getSelectOptions( fontSizes, disableCustomFontSizes );
const rangeControlNumberId = `components-range-control__number#${ instanceId }`;
return (
<fieldset className="components-font-size-picker">
Expand Down Expand Up @@ -112,7 +120,7 @@ function FontSizePicker( {
label={ __( 'Custom Size' ) }
value={ value || '' }
initialPosition={ fallbackFontSize }
onChange={ onChange }
onChange={ onSliderChangeValue }
min={ 12 }
max={ 100 }
beforeIcon="editor-textcolor"
Expand Down