@fluentui/react-northstar
Version:
A themable React component library.
64 lines (63 loc) • 1.84 kB
JavaScript
export var ContainerFocusHandler = /*#__PURE__*/function () {
function ContainerFocusHandler(getItemsCount, setFocusAt, circular) {
var _this = this;
if (circular === void 0) {
circular = false;
}
this.getItemsCount = getItemsCount;
this.setFocusAt = setFocusAt;
this.circular = circular;
this.focusedIndex = 0;
this.noItems = function () {
return _this.getItemsCount() === 0;
};
}
var _proto = ContainerFocusHandler.prototype;
_proto.constrainFocusedIndex = function constrainFocusedIndex() {
var itemsCount = this.getItemsCount();
if (this.focusedIndex < 0) {
this.focusedIndex = this.circular ? itemsCount - 1 : 0;
}
if (this.focusedIndex >= itemsCount) {
this.focusedIndex = this.circular ? 0 : itemsCount - 1;
}
};
_proto.getFocusedIndex = function getFocusedIndex() {
return this.focusedIndex;
};
_proto.syncFocusedIndex = function syncFocusedIndex(withCurrentIndex) {
this.focusedIndex = withCurrentIndex;
};
_proto.movePrevious = function movePrevious() {
if (this.noItems()) {
return;
}
this.focusedIndex -= 1;
this.constrainFocusedIndex();
this.setFocusAt(this.focusedIndex);
};
_proto.moveNext = function moveNext() {
if (this.noItems()) {
return;
}
this.focusedIndex += 1;
this.constrainFocusedIndex();
this.setFocusAt(this.focusedIndex);
};
_proto.moveFirst = function moveFirst() {
if (this.noItems()) {
return;
}
this.focusedIndex = 0;
this.setFocusAt(this.focusedIndex);
};
_proto.moveLast = function moveLast() {
if (this.noItems()) {
return;
}
this.focusedIndex = this.getItemsCount() - 1;
this.setFocusAt(this.focusedIndex);
};
return ContainerFocusHandler;
}();
//# sourceMappingURL=FocusContainer.js.map