Skip to content

Commit

Permalink
[EuiColorStops] ignore empty values when getting range max and min (#…
Browse files Browse the repository at this point in the history
…2496)

* ignore empty values when getting range max and min

* update change log with PR URL

* check for empty string instead of isNaN

* use original check for NaN instead of empty string
  • Loading branch information
nreese authored Oct 28, 2019
1 parent 94cf858 commit b21509d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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 => !isNaN(stop));
}

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

0 comments on commit b21509d

Please sign in to comment.