Skip to content

Commit

Permalink
EuiRange and EuiDualRange fixes (#1580)
Browse files Browse the repository at this point in the history
* EuiRange bug fixing

- Give the inputs a min-width in case of single digits. And remove shifting of inputs because they then don’t line up with other form rows
- Custom tick values now properly account for minimum value
- Fix styling of track color when not showing the range
- Top level `className` should be applied to the top level wrapper
- Better error handling of invalid steps/ticks

* Fixed validations

* Update docs page by splitting up examples

- Also fixed prepend/append of value

* Working commit:

Not worrying about what handle was clicked…

* Handle invalid alternative

* Bug fix: Dual range inputs account for both min and max for sizing

* range tooltip no shrink

* Fixed color of selected & disabled dual range handles

* remove console.log

* Only auto-move invalid handles

* Revert icon snaps

* Created more jest tests

* cl

* handle keyboard value changes when values are intially empty

* Remove unneeded check

* Using var for snippet replacement props
  • Loading branch information
cchaos authored Feb 25, 2019
1 parent 430b4c6 commit babf10c
Show file tree
Hide file tree
Showing 27 changed files with 1,589 additions and 439 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- Added `displayOnly` prop to EuiFormRow ([#1582](https://github.com/elastic/eui/pull/1582))
- Added an index.d.ts file for the date picker components, including `EuiDatePicker`, `EuiDatePickerRange`, and `EuiSuperDatePicker` ([#1574](https://github.com/elastic/eui/pull/1574))

**Bug fixes**

- Fixed several bugs with `EuiRange` and `EuiDualRange` including sizing of inputs, tick placement, and the handling of invalid values ([#1580](https://github.com/elastic/eui/pull/1580))

## [`7.2.0`](https://github.com/elastic/eui/tree/v7.2.0)

- Added `text` as a color option for `EuiLink` ([#1571](https://github.com/elastic/eui/pull/1571))
Expand Down
117 changes: 10 additions & 107 deletions src-docs/src/views/range/dual_range.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React, {
Component,
Fragment,
} from 'react';

import {
EuiDualRange,
EuiSpacer,
EuiFormHelpText,
} from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';
Expand All @@ -15,21 +12,8 @@ export default class extends Component {
constructor(props) {
super(props);

this.levels = [
{
min: 0,
max: 600,
color: 'danger'
},
{
min: 600,
max: 2000,
color: 'success'
}
];

this.state = {
value: [120, 480]
value: ['', ''],
};
}

Expand All @@ -41,96 +25,15 @@ export default class extends Component {

render() {
return (
<Fragment>

<EuiDualRange
id={makeId()}
min={0}
max={2000}
value={this.state.value}
onChange={this.onChange}
aria-label="Use aria labels when no actual label is in use"
showLabels
name="dualRange"
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
min={0}
max={2000}
value={this.state.value}
onChange={this.onChange}
disabled
aria-label="Use aria labels when no actual label is in use"
showLabels
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
min={0}
max={2000}
value={this.state.value}
onChange={this.onChange}
aria-label="Use aria labels when no actual label is in use"
showLabels
showInput
showRange
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
min={0}
max={2000}
step={50}
value={this.state.value}
onChange={this.onChange}
aria-label="Use aria labels when no actual label is in use"
aria-describedby="levelsHelp"
showLabels
showInput
compressed
levels={this.levels}
/>
<EuiFormHelpText id="levelsHelp">Recommended levels are 600 and above.</EuiFormHelpText>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
min={0}
max={2000}
step={50}
value={this.state.value}
onChange={this.onChange}
aria-label="Use aria labels when no actual label is in use"
showTicks
showRange
tickInterval={300}
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
min={0}
max={2000}
step={50}
value={this.state.value}
onChange={this.onChange}
aria-label="Use aria labels when no actual label is in use"
aria-describedby="levelsHelp"
showTicks
showInput
tickInterval={500}
levels={this.levels}
/>
</Fragment>
<EuiDualRange
id={makeId()}
min={-100}
max={200}
step={10}
value={this.state.value}
onChange={this.onChange}
showLabels
/>
);
}
}
57 changes: 57 additions & 0 deletions src-docs/src/views/range/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, {
Component,
Fragment,
} from 'react';

import {
EuiRange,
EuiSpacer,
EuiDualRange,
} from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';

export default class extends Component {
constructor(props) {
super(props);

this.state = {
value: '20',
dualValue: [20, 100],
};
}

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

onDualChange = (value) => {
this.setState({
dualValue: value
});
};

render() {
return (
<Fragment>
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showInput
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showInput
/>
</Fragment>
);
}
}
80 changes: 80 additions & 0 deletions src-docs/src/views/range/levels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, {
Component,
Fragment,
} from 'react';

import {
EuiRange,
EuiSpacer,
EuiFormHelpText,
EuiDualRange,
} from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';

export default class extends Component {
constructor(props) {
super(props);

this.levels = [
{
min: 0,
max: 20,
color: 'danger'
},
{
min: 20,
max: 100,
color: 'success'
}
];

this.state = {
value: '20',
dualValue: [20, 100],
};
}

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

onDualChange = (value) => {
this.setState({
dualValue: value
});
};

render() {
return (
<Fragment>
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showTicks
tickInterval={20}
levels={this.levels}
aria-describedby="levelsHelp2"
/>
<EuiFormHelpText id="levelsHelp2">Recommended levels are {this.levels[1].min} and above.</EuiFormHelpText>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showTicks
ticks={[{ label: '20kb', value: 20 }, { label: '100kb', value: 100 }]}
showInput
levels={this.levels}
aria-describedby="levelsHelp3"
/>
<EuiFormHelpText id="levelsHelp3">Recommended size is {this.levels[1].min}kb and above.</EuiFormHelpText>
</Fragment>
);
}
}
Loading

0 comments on commit babf10c

Please sign in to comment.