UNPKG

@trail-ui/react

Version:
54 lines (51 loc) 1.52 kB
import { useFocusHandler } from "./chunk-SSX6C2M6.mjs"; // src/editable-table/editable-components/links.tsx import { flexRender } from "@tanstack/react-table"; import { useEffect, useRef } from "react"; import { jsx } from "react/jsx-runtime"; function EditableLink({ cell, rowHeaderId, checkBoxSelectedName }) { const cellRef = useRef(null); const { isCurrentCellFocused, focusCurrentCell, tableRef } = useFocusHandler(cell, false); useEffect(() => { var _a, _b; if (isCurrentCellFocused && ((_a = tableRef.current) == null ? void 0 : _a.contains(document.activeElement))) (_b = cellRef.current) == null ? void 0 : _b.focus(); }, [isCurrentCellFocused]); return /* @__PURE__ */ jsx( "div", { ref: cellRef, id: checkBoxSelectedName === cell.column.id ? rowHeaderId : "", className: "td-content px-2 py-0.5 outline-purple-600", onClick: focusCurrentCell, onKeyDown: (e) => { var _a; if (e.key === "Enter") { const link = (_a = cellRef.current) == null ? void 0 : _a.querySelector("a"); if (!link) return; if (e.ctrlKey || e.metaKey) { window.open(link.href, "_blank"); } else { link.click(); } } }, onFocus: focusCurrentCell, tabIndex: isCurrentCellFocused ? 0 : -1, children: flexRender(cell.column.columnDef.cell, { ...cell.getContext(), tabIndex: -1 }) } ); } export { EditableLink };