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

RangeControl: Fix initialPosition to accept 0 #18611

Merged
merged 2 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/components/src/range-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ function RangeControl( {
parseFloat( newValue )
);
};

const initialFallbackValue = isFinite( initialPosition ) ?
initialPosition : '';

const initialSliderValue = isFinite( currentInputValue ) ?
currentInputValue :
initialPosition || '';
currentInputValue : initialFallbackValue;

return (
<BaseControl
Expand Down
17 changes: 16 additions & 1 deletion packages/components/src/range-control/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import RangeControl from '../';
export default { title: 'Components|RangeControl', component: RangeControl };

const RangeControlWithState = ( props ) => {
const [ value, setValue ] = useState( 5 );
const initialValue = props.value === undefined ? 5 : props.value;
const [ value, setValue ] = useState( initialValue );

return (
<RangeControl
Expand All @@ -37,6 +38,20 @@ export const _default = () => {
);
};

export const InitialValueZero = () => {
const label = text( 'Label', 'How many columns should this use?' );

return (
<RangeControlWithState
initialPosition={ 0 }
label={ label }
max={ 20 }
min={ 0 }
value={ null }
/>
);
};

export const withHelp = () => {
const label = text( 'Label', 'How many columns should this use?' );
const help = text( 'Help Text', 'Please select the number of columns you would like this to contain.' );
Expand Down