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

fix(slider): change prop to stepMultiplier and deprecate stepMuliplier #5251

Merged
merged 6 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 3 additions & 3 deletions packages/react/src/components/Slider/Slider-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ const props = () => ({
min: number('The minimum value (min)', 0),
max: number('The maximum value (max)', 100),
step: number('The step (step)', 1),
stepMuliplier: number(
'The step factor for Shift+arrow keys (stepMuliplier)',
4
stepMultiplier: number(
'The step factor for Shift+arrow keys (stepMultiplier)',
5
),
labelText: text('Label text (labelText)', 'Slider Label'),
minLabel: text('Label for minimum value (minLabel)', ''),
Expand Down
21 changes: 17 additions & 4 deletions packages/react/src/components/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { settings } from 'carbon-components';
import deprecate from '../../prop-types/deprecate';

const { prefix } = settings;

Expand Down Expand Up @@ -87,7 +88,16 @@ export default class Slider extends PureComponent {
* A value determining how much the value should increase/decrease by Shift+arrow keys,
* which will be `(max - min) / stepMuliplier`.
*/
stepMuliplier: PropTypes.number,
stepMuliplier: deprecate(
PropTypes.number,
' The `stepMuliplier` prop has been deprecated in favor of `stepMultiplier`. It will be removed in the next major release.'
),

/**
* A value determining how much the value should increase/decrease by Shift+arrow keys,
* which will be `(max - min) / stepMultiplier`.
*/
stepMultiplier: PropTypes.number,

/**
* The child nodes.
Expand Down Expand Up @@ -123,7 +133,7 @@ export default class Slider extends PureComponent {
static defaultProps = {
hideTextInput: false,
step: 1,
stepMuliplier: 4,
stepMultiplier: 4,
disabled: false,
minLabel: '',
maxLabel: '',
Expand Down Expand Up @@ -204,7 +214,7 @@ export default class Slider extends PureComponent {
};

calcValue = (evt, prevState, props) => {
const { min, max, step, stepMuliplier } = props;
const { min, max, step, stepMuliplier, stepMultiplier } = props;

const { value } = prevState;

Expand All @@ -227,9 +237,11 @@ export default class Slider extends PureComponent {
39: 1, // increasing
}[evt.which];

const multiplyStep = stepMuliplier || stepMultiplier;

if (direction !== undefined) {
const multiplier =
evt.shiftKey === true ? range / step / stepMuliplier : 1;
evt.shiftKey === true ? range / step / multiplyStep : 1;
const stepMultiplied = step * multiplier;
const stepSize = (stepMultiplied / range) * 100;
left = valuePercentage + stepSize * direction;
Expand Down Expand Up @@ -366,6 +378,7 @@ export default class Slider extends PureComponent {
labelText,
step,
stepMuliplier, // eslint-disable-line no-unused-vars
stepMultiplier, // eslint-disable-line no-unused-vars
inputType,
required,
disabled,
Expand Down