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

EuiRange - onValidatedChange props #1461

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `onValidatedChange` prop to `EuiRange` ([#1461](https://github.com/elastic/eui/pull/1461))
- Added `inputRef` prop to `EuiFieldNumber` and updated `EuiFieldText`'s to a Ref type ([#1434](https://github.com/elastic/eui/pull/1434))
- Added `snowflake` icon ([#1445](https://github.com/elastic/eui/pull/1445))

Expand Down
39 changes: 39 additions & 0 deletions src-docs/src/views/form_controls/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
EuiRange,
EuiSpacer,
EuiFormHelpText,
EuiCode,
} from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';
Expand All @@ -30,15 +31,24 @@ export default class extends Component {

this.state = {
value: '120',
validatedValue: '3000',
};
}

onChange = e => {
// onChange called with Event
this.setState({
value: e.target.value,
});
};

onValidatedChange = newValue => {
// onValidatedChange called with Number (not Event like onChange)
this.setState({
validatedValue: newValue
});
};

render() {
return (
<Fragment>
Expand Down Expand Up @@ -131,6 +141,35 @@ export default class extends Component {
tickInterval={500}
levels={this.levels}
/>

<EuiSpacer size="xl" />

<div>
<p>
<EuiCode>onChange</EuiCode> is called with the DOM Event and requires you to extract the value
cchaos marked this conversation as resolved.
Show resolved Hide resolved
and validate that the value is a Number within the specified range.
</p>
<p>
Use <EuiCode>onValidatedChange</EuiCode> callback to only receive updates when the value
changes to a Number that is within the specified range and leave all that error checking
to EuiRange.
</p>
</div>
<EuiSpacer size="s" />
<EuiRange
id={makeId()}
min={2000}
max={5000}
step={50}
value={this.state.validatedValue}
onValidatedChange={this.onValidatedChange}
showInput
showRange
showTicks
showValue
tickInterval={500}
/>

</Fragment>
);
}
Expand Down
13 changes: 9 additions & 4 deletions src/components/form/range/__snapshots__/range.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,14 @@ exports[`EuiRange props range should render 1`] = `
max="100"
min="1"
type="range"
value="50"
/>
<div
class="euiRange__range"
>
<div
class="euiRange__range__progress"
style="width:NaN%"
style="width:49.494949494949495%"
/>
</div>
</div>
Expand All @@ -219,6 +220,7 @@ exports[`EuiRange props ticks should render 1`] = `
max="100"
min="1"
type="range"
value="50"
/>
<div
class="euiRange__ticks"
Expand Down Expand Up @@ -286,14 +288,17 @@ exports[`EuiRange props value should render 1`] = `
max="100"
min="1"
type="range"
value="50"
/>
<div
class="euiRange__valueWrapper"
>
<output
class="euiRange__value euiRange__value--left"
style="left:100%"
/>
class="euiRange__value euiRange__value--right"
style="left:49.494949494949495%"
>
50
</output>
</div>
</div>
</div>
Expand Down
Loading