1+ import type { FullTheme } from "../common/styles.js" ;
12import { getSquareWidth , getSquareXPosFromAlign , getSquareBB , pointIsWithinBB } from "../common/utils.js" ;
23import { toggleBoolean } from "../data-editor/data-editor-fns.js" ;
34import {
@@ -6,12 +7,38 @@ import {
67 booleanCellIsEditable ,
78 BooleanEmpty ,
89 BooleanIndeterminate ,
10+ type Rectangle ,
911} from "../internal/data-grid/data-grid-types.js" ;
1012import { drawCheckbox } from "../internal/data-grid/render/draw-checkbox.js" ;
1113import type { BaseDrawArgs , InternalCellRenderer } from "./cell-types.js" ;
1214
1315const defaultCellMaxSize = 20 ;
1416
17+ function isOverEditableRegion ( e : {
18+ readonly cell : BooleanCell ;
19+ readonly posX : number ;
20+ readonly posY : number ;
21+ readonly bounds : Rectangle ;
22+ readonly theme : FullTheme ;
23+ } ) : boolean {
24+ const { cell, posX : pointerX , posY : pointerY , bounds, theme } = e ;
25+ const { width, height, x : cellX , y : cellY } = bounds ;
26+ const maxWidth = cell . maxSize ?? defaultCellMaxSize ;
27+ const cellCenterY = Math . floor ( bounds . y + height / 2 ) ;
28+ const checkBoxWidth = getSquareWidth ( maxWidth , height , theme . cellVerticalPadding ) ;
29+ const posX = getSquareXPosFromAlign (
30+ cell . contentAlign ?? "center" ,
31+ cellX ,
32+ width ,
33+ theme . cellHorizontalPadding ,
34+ checkBoxWidth
35+ ) ;
36+ const bb = getSquareBB ( posX , cellCenterY , checkBoxWidth ) ;
37+ const checkBoxClicked = pointIsWithinBB ( cellX + pointerX , cellY + pointerY , bb ) ;
38+
39+ return booleanCellIsEditable ( cell ) && checkBoxClicked ;
40+ }
41+
1542export const booleanCellRenderer : InternalCellRenderer < BooleanCell > = {
1643 getAccessibilityString : c => c . data ?. toString ( ) ?? "false" ,
1744 kind : GridCellKind . Boolean ,
@@ -31,26 +58,16 @@ export const booleanCellRenderer: InternalCellRenderer<BooleanCell> = {
3158 ...c ,
3259 data : false ,
3360 } ) ,
61+ onSelect : e => {
62+ if ( isOverEditableRegion ( e ) ) {
63+ e . preventDefault ( ) ;
64+ }
65+ } ,
3466 onClick : e => {
35- const { cell, posX : pointerX , posY : pointerY , bounds, theme } = e ;
36- const { width, height, x : cellX , y : cellY } = bounds ;
37- const maxWidth = cell . maxSize ?? defaultCellMaxSize ;
38- const cellCenterY = Math . floor ( bounds . y + height / 2 ) ;
39- const checkBoxWidth = getSquareWidth ( maxWidth , height , theme . cellVerticalPadding ) ;
40- const posX = getSquareXPosFromAlign (
41- cell . contentAlign ?? "center" ,
42- cellX ,
43- width ,
44- theme . cellHorizontalPadding ,
45- checkBoxWidth
46- ) ;
47- const bb = getSquareBB ( posX , cellCenterY , checkBoxWidth ) ;
48- const checkBoxClicked = pointIsWithinBB ( cellX + pointerX , cellY + pointerY , bb ) ;
49-
50- if ( booleanCellIsEditable ( cell ) && checkBoxClicked ) {
67+ if ( isOverEditableRegion ( e ) ) {
5168 return {
52- ...cell ,
53- data : toggleBoolean ( cell . data ) ,
69+ ...e . cell ,
70+ data : toggleBoolean ( e . cell . data ) ,
5471 } ;
5572 }
5673 return undefined ;
0 commit comments