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:
@ -6,7 +6,7 @@ import { IconCheck, IconMinus } from '@/ui/icon';
|
|||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
indeterminate?: boolean;
|
indeterminate?: boolean;
|
||||||
onChange: (value: boolean) => void;
|
onChange?: (value: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledInputContainer = styled.div`
|
const StyledInputContainer = styled.div`
|
||||||
@ -71,7 +71,7 @@ export function Checkbox({ checked, onChange, indeterminate }: OwnProps) {
|
|||||||
}, [checked]);
|
}, [checked]);
|
||||||
|
|
||||||
function handleChange(value: boolean) {
|
function handleChange(value: boolean) {
|
||||||
onChange(value);
|
onChange?.(value);
|
||||||
setIsInternalChecked(!isInternalChecked);
|
setIsInternalChecked(!isInternalChecked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import * as React from 'react';
|
import { useCallback } from 'react';
|
||||||
import styled from '@emotion/styled';
|
import styled from '@emotion/styled';
|
||||||
import { useSetRecoilState } from 'recoil';
|
import { useSetRecoilState } from 'recoil';
|
||||||
|
|
||||||
@ -9,6 +9,7 @@ import { contextMenuPositionState } from '../states/contextMenuPositionState';
|
|||||||
|
|
||||||
const StyledContainer = styled.div`
|
const StyledContainer = styled.div`
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
height: 32px;
|
height: 32px;
|
||||||
@ -21,19 +22,14 @@ export function CheckboxCell() {
|
|||||||
|
|
||||||
const { currentRowSelected, setCurrentRowSelected } = useCurrentRowSelected();
|
const { currentRowSelected, setCurrentRowSelected } = useCurrentRowSelected();
|
||||||
|
|
||||||
function onChange(checked: boolean) {
|
const handleClick = useCallback(() => {
|
||||||
handleCheckboxChange(checked);
|
setCurrentRowSelected(!currentRowSelected);
|
||||||
}
|
|
||||||
|
|
||||||
function handleCheckboxChange(newCheckedValue: boolean) {
|
|
||||||
setCurrentRowSelected(newCheckedValue);
|
|
||||||
|
|
||||||
setContextMenuPosition({ x: null, y: null });
|
setContextMenuPosition({ x: null, y: null });
|
||||||
}
|
}, [currentRowSelected, setContextMenuPosition, setCurrentRowSelected]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledContainer>
|
<StyledContainer onClick={handleClick}>
|
||||||
<Checkbox checked={currentRowSelected} onChange={onChange} />
|
<Checkbox checked={currentRowSelected} />
|
||||||
</StyledContainer>
|
</StyledContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user