feat: select line on checkbox container click (#732)

* feat: select line on checkbox container click

Closes #703

* Make onChange optional

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Thaïs
2023-07-18 19:00:48 +02:00
committed by GitHub
parent fdb2011a96
commit 5d4fad2d96
2 changed files with 9 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import * as React from 'react';
import { useCallback } from 'react';
import styled from '@emotion/styled';
import { useSetRecoilState } from 'recoil';
@ -9,6 +9,7 @@ import { contextMenuPositionState } from '../states/contextMenuPositionState';
const StyledContainer = styled.div`
align-items: center;
cursor: pointer;
display: flex;
height: 32px;
@ -21,19 +22,14 @@ export function CheckboxCell() {
const { currentRowSelected, setCurrentRowSelected } = useCurrentRowSelected();
function onChange(checked: boolean) {
handleCheckboxChange(checked);
}
function handleCheckboxChange(newCheckedValue: boolean) {
setCurrentRowSelected(newCheckedValue);
const handleClick = useCallback(() => {
setCurrentRowSelected(!currentRowSelected);
setContextMenuPosition({ x: null, y: null });
}
}, [currentRowSelected, setContextMenuPosition, setCurrentRowSelected]);
return (
<StyledContainer>
<Checkbox checked={currentRowSelected} onChange={onChange} />
<StyledContainer onClick={handleClick}>
<Checkbox checked={currentRowSelected} />
</StyledContainer>
);
}