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

[EuiColorStops] ignore empty values when getting range max and min #2496

Merged
merged 4 commits into from
Oct 28, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Added new `euiTreeView` component for rendering recursive objects such as folder structures. ([#2409](https://github.com/elastic/eui/pull/2409))
- Added `euiXScrollWithShadows()` mixin and `.eui-xScrollWithShadows` utility class ([#2458](https://github.com/elastic/eui/pull/2458))
- Fixed `EuiColorStops` where empty string values would cause range min or max to be NaN ([#2496](https://github.com/elastic/eui/pull/2496))

**Bug fixes**

Expand Down
8 changes: 6 additions & 2 deletions src/components/color_picker/color_stops/color_stops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ function sortStops(colorStops: ColorStop[]) {
.sort((a, b) => a.stop - b.stop);
}

function getValidStops(colorStops: ColorStop[]) {
return colorStops.map(el => el.stop).filter(stop => stop !== '');
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
}

function getRangeMin(colorStops: ColorStop[], min?: number) {
const rangeMin = min || DEFAULT_MIN;
const stops = colorStops.map(el => el.stop);
const stops = getValidStops(colorStops);
const first = Math.min.apply(Math, stops); // https://johnresig.com/blog/fast-javascript-maxmin/

if (first < rangeMin) {
Expand All @@ -78,7 +82,7 @@ function getRangeMin(colorStops: ColorStop[], min?: number) {
}
function getRangeMax(colorStops: ColorStop[], max?: number) {
const rangeMax = max || DEFAULT_MAX;
const stops = colorStops.map(el => el.stop);
const stops = getValidStops(colorStops);
const last = Math.max.apply(Math, stops); // https://johnresig.com/blog/fast-javascript-maxmin/

if (last > rangeMax) {
Expand Down