Skip to content

Commit

Permalink
[kbn-number-list] avoid adding new items that are outside of the range (
Browse files Browse the repository at this point in the history
#28304)

* dont add value outside of range

* handle last being over max

* return NaN for next when list is empty
  • Loading branch information
nreese authored Jan 11, 2019
1 parent ce956f0 commit d707679
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ui/public/number_list/number_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,22 @@ uiModules
const list = self.getList();
if (!list) return;

list.push(_.last(list) + 1);
function getNext() {
if (list.length === 0) {
// returning NaN adds an empty input
return NaN;
}

const next = _.last(list) + 1;
if (next < self.range.max) {
return next;
}

return self.range.max - 1;
}

const next = getNext();
list.push(next);
};

/**
Expand Down

0 comments on commit d707679

Please sign in to comment.