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

EuiDualRange component #1485

Merged
merged 34 commits into from
Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6146f3d
WIP: range component break down; dualRange inital
thompsongl Jan 24, 2019
b781aee
WIP: dual range docs examples
thompsongl Jan 25, 2019
b5fabbc
WIP: propTypes; type def updates; baseline keyboard nav
thompsongl Jan 25, 2019
9cbe793
WIP: hasFocus for range highlight
thompsongl Jan 25, 2019
6b6acbd
WIP: better rangeSlider ref access
thompsongl Jan 25, 2019
e859174
WIP: sass refactor using component boundaries
thompsongl Jan 26, 2019
1fbd0b5
update euiRange tests; create euiDualRange tests
thompsongl Jan 28, 2019
a6eb6e7
move range examples out of formControl; clean up
thompsongl Jan 28, 2019
90ff293
remove thumb focus when disabled
thompsongl Jan 28, 2019
e3672ea
update docs to share intro
thompsongl Jan 28, 2019
e7ade55
default showRange to true for EuiDualRange; prop clean up
thompsongl Jan 28, 2019
0f162bb
class-based focus style when input is not focusable
thompsongl Jan 29, 2019
b4e3dc2
size input based on max number of characters via digits prop
thompsongl Jan 29, 2019
2c1954a
pass aria attrs through to focusable, changeable elements
thompsongl Jan 29, 2019
a404ee7
number service: isWithinRange
thompsongl Jan 30, 2019
a742311
account for invalid states; pass isValid to parent via onChange
thompsongl Jan 30, 2019
a3dbc93
number service tests, scss whitespace clean up, onChange fn signature…
thompsongl Jan 30, 2019
ee6116c
allow for empty string input value to prevent constant 0
thompsongl Jan 30, 2019
3e1fc05
Merge branch 'master' into 496-dual-range
thompsongl Jan 30, 2019
a03e156
#1485 euiDualRange changelog update
thompsongl Jan 30, 2019
e94f1b2
logic to always enable a valid state during thumb interactions
thompsongl Jan 31, 2019
1e2db88
comments for thumb positioning logic
thompsongl Jan 31, 2019
4a73521
Merge branch 'master' into 496-dual-range
thompsongl Feb 1, 2019
2db20b4
handle keyboard value stepping better; remove pseudo value from dual …
thompsongl Feb 1, 2019
774935e
better thumb swap logic; docs notice about value retrieval
thompsongl Feb 1, 2019
5dc15bf
Merge branch 'master' into 496-dual-range
thompsongl Feb 1, 2019
0a17e9f
Merge branch 'master' into 496-dual-range
thompsongl Feb 4, 2019
79b84d1
Merge branch 'master' into 496-dual-range
thompsongl Feb 5, 2019
b9817a0
ts fixes; isWithinRange simplification
thompsongl Feb 5, 2019
3051f73
min and max 0-length check
thompsongl Feb 5, 2019
5d3cd63
Merge branch 'master' into 496-dual-range
thompsongl Feb 6, 2019
4156dc3
rangeClasses -> sliderClasses
cchaos Feb 6, 2019
6712617
move all components to individual files
thompsongl Feb 6, 2019
1d8e323
Merge branch 'master' into 496-dual-range
thompsongl Feb 6, 2019
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
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `6.9.0`.
- Created `EuiDualRange` using components from modularized, refactored `EuiRange`. New util service `isWithinRange` is the first in the number category. ([#1485](https://github.com/elastic/eui/pull/1485))

## [`6.9.0`](https://github.com/elastic/eui/tree/v6.9.0)

- Changed animation settings for `EuiNavDrawer` ([#1524](https://github.com/elastic/eui/pull/1524))
- Converted a number of components to support text localization ([#1504](https://github.com/elastic/eui/pull/1504))
- Created `EuiDualRange` using components from modularized, refactored `EuiRange`. New util service `isWithinRange` is the first in the number category. ([#1485](https://github.com/elastic/eui/pull/1485))
- Updated `app_ems.svg` ([#1517](https://github.com/elastic/eui/pull/1517))

**Bug fixes**

- Updated `EuiPage` background color to match body background color ([#1513](https://github.com/elastic/eui/pull/1513))
- Fixed React key usage in `EuiPagination` ([#1514](https://github.com/elastic/eui/pull/1514))
- Fixed bug which prevented `EuiSwitch` with generated ID from having its label announced by VoiceOver ([#1519](https://github.com/elastic/eui/pull/1519))
- Fixed `EuiFilterButton` handling `numFilters` when `0` was specified ([#1510](https://github.com/elastic/eui/pull/1510))

## [`6.8.0`](https://github.com/elastic/eui/tree/v6.8.0)

Expand Down
20 changes: 10 additions & 10 deletions src/components/form/range/dual_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,25 +123,25 @@ export class EuiDualRange extends Component {

_handleKeyDown = (value, e) => {
let newVal = Number(value);
let changeRemainder = 0;
const change = this.props.step || 1;
let stepRemainder = 0;
const step = this.props.step || 1;
switch (e.keyCode) {
case keyCodes.UP:
case keyCodes.RIGHT:
e.preventDefault();
newVal += change;
changeRemainder = (newVal - this.props.min) % change;
if (change !== 1 && changeRemainder > 0) {
newVal = newVal - changeRemainder;
newVal += step;
stepRemainder = (newVal - this.props.min) % step;
if (step !== 1 && stepRemainder > 0) {
newVal = newVal - stepRemainder;
}
break;
case keyCodes.DOWN:
case keyCodes.LEFT:
e.preventDefault();
newVal -= change;
changeRemainder = (newVal - this.props.min) % change;
if (change !== 1 && changeRemainder > 0) {
newVal = newVal + (change - changeRemainder);
newVal -= step;
stepRemainder = (newVal - this.props.min) % step;
if (step !== 1 && stepRemainder > 0) {
newVal = newVal + (step - stepRemainder);
}
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/form/range/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommonProps } from '../../common';
import { CommonProps, Omit } from '../../common';

import { SFC, ReactNode, HTMLAttributes, ChangeEventHandler, InputHTMLAttributes } from 'react';

Expand Down Expand Up @@ -43,10 +43,10 @@ declare module '@elastic/eui' {

export interface EuiDualRangeProps {
// Override acceptable value type
value: Array<number | string>
value: [number | string, number | string]
}

export const EuiDualRange: SFC<
CommonProps & InputHTMLAttributes<HTMLInputElement> & EuiRangeProps & EuiDualRangeProps
CommonProps & Omit<InputHTMLAttributes<HTMLInputElement>, 'value'> & EuiRangeProps & EuiDualRangeProps
>;
}
4 changes: 4 additions & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export {
formatText,
} from './format';

export {
isWithinRange,
} from './number';

export {
Pager
} from './paging';
Expand Down
3 changes: 0 additions & 3 deletions src/services/number/number.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ describe('numbers', () => {
expect(isWithinRange(10, 100, 0)).toBe(false);
expect(isWithinRange(0, 100, -10)).toBe(false);
expect(isWithinRange(0, 100, '')).toBe(false);
expect(isWithinRange(0, 100, null)).toBe(false);
expect(isWithinRange(0, 100)).toBe(false);
expect(isWithinRange(0, 100, 'a')).toBe(false);
});
});
14 changes: 3 additions & 11 deletions src/services/number/number.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import { isNil } from '../predicate';

export const isWithinRange = (min?: any, max?: any, value?: any) => {
if (isNil(value) || isNaN(value) || value === '') {
export const isWithinRange = (min: number | string, max: number | string, value: number | string) => {
if (value === '') {
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

min = Number(min);
max = Number(max);
value = Number(value);
if (value >= min && value <= max) {
return true;
}
return false;
return min <= value && value <= max;
};