UNPKG

@progress/kendo-react-common

Version:

React Common package delivers common utilities that can be used with the KendoReact UI components. KendoReact Common Utilities package

68 lines (67 loc) 1.97 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ import { Keys as r } from "./keys.mjs"; import { FOCUSABLE_ELEMENTS as u } from "./constants/main.mjs"; const c = (s, f = u) => s.querySelectorAll(f.join(",")), a = (s, f = u) => { if (s) { const t = c(s, f); if (t.length && t[0].focus) return t[0]; } }, l = (s, f = u) => { if (s) { const t = c(s, f); if (t.length && t[t.length - 1].focus) return t[t.length - 1]; } }, e = (s, f) => { if (s) { const t = a(s, f); t && t.focus(); } }, b = (s, f) => { if (s) { const t = l(s, f); t && t.focus(); } }, n = (s, f, t) => { if (!(!f || s.keyCode !== r.tab) && f) { const o = a(f, t), i = l(f, t); o && i && !s.shiftKey && s.target === i && (s.preventDefault(), o.focus()), o && i && s.shiftKey && s.target === o && (s.preventDefault(), i.focus()), o || s.preventDefault(); } }, d = (s, f, t, o) => { let i = !0; if (s.keyCode !== r.enter && s.target === f) { t && t(!1); return; } s.keyCode === r.enter && s.target === f ? (i = !0, setTimeout(() => { e(f, o); }, 1)) : s.keyCode === r.esc ? (i = !1, f.focus()) : n(s, f, o), t && t(i); }, g = (s, f) => { const t = c(s, f); t && t.forEach((o) => { o.tabIndex = 0; }); }, y = (s, f) => { const t = c(s, f); t && t.forEach((o) => { o.tabIndex = -1; }); }; export { d as applyTrappedFocus, y as disableNavigatableContainer, g as enableNavigatableContainer, a as firstFocusableChild, e as focusFirstFocusableChild, b as focusLastFocusableChild, c as focusableChildren, n as keepFocusInContainer, l as lastFocusableChild };