[kbn-number-list] avoid adding new items that are outside of the range (#28304) (#28634)

* dont add value outside of range

* handle last being over max

* return NaN for next when list is empty
This commit is contained in:
Nathan Reese 2019-01-12 07:50:45 -07:00 committed by GitHub
parent 010a998bac
commit 593423bd46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
};
/**