Skip to content
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
49 changes: 38 additions & 11 deletions src-docs/src/views/range/dual_range.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React, { Component } from 'react';
import React, { Component, Fragment } from 'react';

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

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

Expand All @@ -10,6 +14,7 @@ export default class extends Component {

this.state = {
value: ['', ''],
value2: ['20', '150'],
};
}

Expand All @@ -19,17 +24,39 @@ export default class extends Component {
});
};

onChange2 = value => {
this.setState({
value2: value,
});
};

render() {
return (
<EuiDualRange
id={makeId()}
min={-100}
max={200}
step={10}
value={this.state.value}
onChange={this.onChange}
showLabels
/>
<Fragment>
<EuiFormRow label="Dual range">
<EuiDualRange
id={makeId()}
min={-100}
max={200}
step={10}
value={this.state.value}
onChange={this.onChange}
showLabels
/>
</EuiFormRow>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
min={-100}
max={200}
step={10}
value={this.state.value2}
onChange={this.onChange2}
showLabels
/>
</Fragment>
);
}
}
35 changes: 22 additions & 13 deletions src-docs/src/views/range/input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React, { Component, Fragment } from 'react';

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

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

Expand Down Expand Up @@ -29,21 +34,25 @@ export default class extends Component {
render() {
return (
<Fragment>
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showInput
/>
<EuiFormRow label="Single">
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showInput
/>
</EuiFormRow>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showInput
/>
<EuiFormRow label="Dual">
<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showInput
/>
</EuiFormRow>
</Fragment>
);
}
Expand Down
25 changes: 16 additions & 9 deletions src-docs/src/views/range/input_only.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React, { Component, Fragment } from 'react';

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

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

Expand Down Expand Up @@ -63,14 +68,16 @@ export default class extends Component {

<EuiSpacer size="xl" />

<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
compressed
showInput="inputWithPopover"
showLabels
/>
<EuiFormRow label="With label">
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
compressed
showInput="inputWithPopover"
showLabels
/>
</EuiFormRow>

<EuiSpacer size="xl" />

Expand Down
22 changes: 12 additions & 10 deletions src-docs/src/views/range/range.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component, Fragment } from 'react';

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

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

Expand All @@ -22,15 +22,17 @@ export default class extends Component {
render() {
return (
<Fragment>
<EuiRange
id={makeId()}
min={100}
max={200}
step={0.05}
value={this.state.value}
onChange={this.onChange}
showLabels
/>
<EuiFormRow label="Single range">
<EuiRange
id={makeId()}
min={100}
max={200}
step={0.05}
value={this.state.value}
onChange={this.onChange}
showLabels
/>
</EuiFormRow>

<EuiSpacer size="xl" />

Expand Down
76 changes: 56 additions & 20 deletions src/components/form/range/dual_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export class EuiDualRange extends Component {
rangeWidth: null,
};

maxNode = null;
minNode = null;
preventPopoverClose = false;
rangeSliderRef = null;
handleRangeSliderRefUpdate = ref => {
this.rangeSliderRef = ref;
Expand Down Expand Up @@ -234,21 +233,48 @@ export class EuiDualRange extends Component {
});
};

onInputFocus = () => {
onThumbFocus = e => {
if (this.props.onFocus) {
this.props.onFocus(e);
}
this.toggleHasFocus(true);
};

onThumbBlur = e => {
if (this.props.onBlur) {
this.props.onBlur(e);
}
this.toggleHasFocus(false);
};

onInputFocus = e => {
if (this.props.onFocus) {
this.props.onFocus(e);
}
this.preventPopoverClose = true;
this.setState({
isPopoverOpen: true,
});
};

onInputBlur = e => {
// Firefox returns `relatedTarget` as `null` for security reasons, but provides a proprietary `explicitOriginalTarget`
const relatedTarget = e.relatedTarget || e.explicitOriginalTarget;
if (!relatedTarget || relatedTarget.id !== this.state.id) {
onInputBlur = e =>
setTimeout(() => {
// Safari does not recognize any focus-related eventing for input[type=range]
// making it impossible to capture its state using active/focus/relatedTarget
// Instead, a prevention flag is set on mousedown, with a waiting period here.
// Mousedown is viable because in the popover case, it is inaccessable via keyboard (intentionally)
if (this.preventPopoverClose) {
this.preventPopoverClose = false;
return;
}
if (this.props.onBlur) {
this.props.onBlur(e);
}
this.closePopover();
}
};
}, 200);

closePopover = () => {
this.preventPopoverClose = false;
this.setState({
isPopoverOpen: false,
});
Expand All @@ -261,10 +287,10 @@ export class EuiDualRange extends Component {
};

inputRef = (node, ref) => {
if (!this.props.showInput !== 'inputWithPopover') return;
if (this.props.showInput !== 'inputWithPopover') return;

// IE11 doesn't support the `relatedTarget` event property for blur events
// but does add it for focusout. React doesn't support `onFocusOut` so here we are.
// IE11 and Safari don't support the `relatedTarget` event property for blur events
// but do add it for focusout. React doesn't support `onFocusOut` so here we are.
if (this[ref] != null) {
this[ref].removeEventListener('focusout', this.onInputBlur);
}
Expand Down Expand Up @@ -294,7 +320,9 @@ export class EuiDualRange extends Component {
tickInterval,
ticks,
levels,
onBlur,
onChange,
onFocus,
showRange,
value,
style,
Expand Down Expand Up @@ -322,12 +350,15 @@ export class EuiDualRange extends Component {
name={`${name}-minValue`}
aria-describedby={this.props['aria-describedby']}
aria-label={this.props['aria-label']}
onFocus={canShowDropdown ? this.onInputFocus : undefined}
onFocus={canShowDropdown ? this.onInputFocus : onFocus}
onBlur={canShowDropdown ? this.onInputBlur : onBlur}
readOnly={readOnly}
autoSize={!showInputOnly}
fullWidth={!!showInputOnly && fullWidth}
controlOnly={showInputOnly}
inputRef={node => this.inputRef(node, 'minNode')}
onMouseDown={
showInputOnly ? () => (this.preventPopoverClose = true) : null
}
/>
) : (
undefined
Expand All @@ -348,12 +379,15 @@ export class EuiDualRange extends Component {
name={`${name}-maxValue`}
aria-describedby={this.props['aria-describedby']}
aria-label={this.props['aria-label']}
onFocus={canShowDropdown ? this.onInputFocus : undefined}
onFocus={canShowDropdown ? this.onInputFocus : onFocus}
onBlur={canShowDropdown ? this.onInputBlur : onBlur}
readOnly={readOnly}
autoSize={!showInputOnly}
fullWidth={!!showInputOnly && fullWidth}
controlOnly={showInputOnly}
inputRef={node => this.inputRef(node, 'maxNode')}
onMouseDown={
showInputOnly ? () => (this.preventPopoverClose = true) : null
}
/>
) : (
undefined
Expand Down Expand Up @@ -412,6 +446,8 @@ export class EuiDualRange extends Component {
aria-hidden={true}
tabIndex={-1}
showRange={showRange}
onFocus={onFocus}
onBlur={onBlur}
{...rest}
/>

Expand All @@ -425,8 +461,8 @@ export class EuiDualRange extends Component {
showTicks={showTicks}
showInput={!!showInput}
onKeyDown={this.handleLowerKeyDown}
onFocus={() => this.toggleHasFocus(true)}
onBlur={() => this.toggleHasFocus(false)}
onFocus={this.onThumbFocus}
onBlur={this.onThumbBlur}
style={this.calculateThumbPositionStyle(
this.lowerValue || min,
this.state.rangeWidth
Expand All @@ -442,8 +478,8 @@ export class EuiDualRange extends Component {
showTicks={showTicks}
showInput={!!showInput}
onKeyDown={this.handleUpperKeyDown}
onFocus={() => this.toggleHasFocus(true)}
onBlur={() => this.toggleHasFocus(false)}
onFocus={this.onThumbFocus}
onBlur={this.onThumbBlur}
style={this.calculateThumbPositionStyle(
this.upperValue || max,
this.state.rangeWidth
Expand Down
Loading