UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

21 lines (20 loc) 833 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listItemRemove = void 0; const useCursorListModel_1 = require("./useCursorListModel"); const listItemRemove = (id, model) => { var _a; // bail early if an ID isn't available if (!id) { return; } const index = model.state.items.findIndex(item => item.id === model.state.cursorId); const nextIndex = index === model.state.items.length - 1 ? index - 1 : index + 1; const nextId = (_a = model.state.items[nextIndex]) === null || _a === void 0 ? void 0 : _a.id; if (nextId && (0, useCursorListModel_1.isCursor)(model.state, id)) { // We're removing the currently focused item. Focus next item model.events.goTo({ id: nextId }); } return nextId; }; exports.listItemRemove = listItemRemove;