Only respect keyboard events in grids when the mouse is over them
This commit is contained in:
parent
73cae6198f
commit
86265a90e0
|
@ -80,6 +80,7 @@
|
||||||
loading,
|
loading,
|
||||||
rowHeight,
|
rowHeight,
|
||||||
contentLines,
|
contentLines,
|
||||||
|
gridFocused,
|
||||||
} = context
|
} = context
|
||||||
|
|
||||||
// Keep stores up to date
|
// Keep stores up to date
|
||||||
|
@ -116,6 +117,8 @@
|
||||||
class:is-reordering={$isReordering}
|
class:is-reordering={$isReordering}
|
||||||
class:stripe={$config.stripeRows}
|
class:stripe={$config.stripeRows}
|
||||||
style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-height:{MaxCellRenderHeight}px; --max-cell-render-width-overflow:{MaxCellRenderWidthOverflow}px; --content-lines:{$contentLines};"
|
style="--row-height:{$rowHeight}px; --default-row-height:{DefaultRowHeight}px; --gutter-width:{GutterWidth}px; --max-cell-render-height:{MaxCellRenderHeight}px; --max-cell-render-width-overflow:{MaxCellRenderWidthOverflow}px; --content-lines:{$contentLines};"
|
||||||
|
on:mouseenter={() => gridFocused.set(true)}
|
||||||
|
on:mouseleave={() => gridFocused.set(false)}
|
||||||
>
|
>
|
||||||
{#if showControls}
|
{#if showControls}
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
selectedRows,
|
selectedRows,
|
||||||
config,
|
config,
|
||||||
menu,
|
menu,
|
||||||
|
gridFocused,
|
||||||
} = getContext("grid")
|
} = getContext("grid")
|
||||||
|
|
||||||
const ignoredOriginSelectors = [
|
const ignoredOriginSelectors = [
|
||||||
|
@ -24,6 +25,11 @@
|
||||||
|
|
||||||
// Global key listener which intercepts all key events
|
// Global key listener which intercepts all key events
|
||||||
const handleKeyDown = e => {
|
const handleKeyDown = e => {
|
||||||
|
// Ignore completely if the grid is not focused
|
||||||
|
if (!$gridFocused) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Avoid processing events sourced from certain origins
|
// Avoid processing events sourced from certain origins
|
||||||
if (e.target?.closest) {
|
if (e.target?.closest) {
|
||||||
for (let selector of ignoredOriginSelectors) {
|
for (let selector of ignoredOriginSelectors) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ export const createStores = () => {
|
||||||
const hoveredRowId = writable(null)
|
const hoveredRowId = writable(null)
|
||||||
const rowHeight = writable(DefaultRowHeight)
|
const rowHeight = writable(DefaultRowHeight)
|
||||||
const previousFocusedRowId = writable(null)
|
const previousFocusedRowId = writable(null)
|
||||||
|
const gridFocused = writable(false)
|
||||||
|
|
||||||
// Derive the current focused row ID
|
// Derive the current focused row ID
|
||||||
const focusedRowId = derived(
|
const focusedRowId = derived(
|
||||||
|
@ -46,6 +47,7 @@ export const createStores = () => {
|
||||||
previousFocusedRowId,
|
previousFocusedRowId,
|
||||||
hoveredRowId,
|
hoveredRowId,
|
||||||
rowHeight,
|
rowHeight,
|
||||||
|
gridFocused,
|
||||||
selectedRows: {
|
selectedRows: {
|
||||||
...selectedRows,
|
...selectedRows,
|
||||||
actions: {
|
actions: {
|
||||||
|
|
Loading…
Reference in New Issue