Skip to content

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
matttdawson committed Jun 30, 2023
1 parent fb9dde1 commit 8f2a3ff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,26 +122,28 @@ const GridDemo = () => {
[],
);

const contextMenu = useCallback(
(selectedRows: IFormTestRow[]): GridContextMenuItem[] => [
{
label: "Clear cell...",
onSelect: async ({ colDef }) => {
selectedRows.forEach((row) => {
switch (colDef.field) {
case "name":
row.name = "";
break;
case "position":
row.position = "";
break;
}
});
},
},
],
[],
);
const ContextMenu = ({ selectedRows, colDef, close }: GridContextMenuComponentProps<IFormTestRow>): ReactElement => {
const onClick = useCallback(() => {
selectedRows.forEach((row) => {
switch (colDef.field) {
case "name":
row.name = "";
break;
case "distance":
row.distance = null;
break;
}
});
close();
}, [close, colDef.field, selectedRows]);

return (
<>
<button onClick={onClick}>Button - Clear cell</button>
<MenuItem onClick={onClick}>Menu Item - Clear cell</MenuItem>
</>
);
};

const rowData: ITestRow[] = useMemo(
() => [
Expand Down Expand Up @@ -179,6 +181,7 @@ const GridDemo = () => {
columnDefs={columnDefs}
rowData={rowData}
contextMenu={contextMenu}
contextMenuSelectRow={false}
onContentSize={({ width }) => setPanelSize(width)} />
</GridWrapper>
</GridContextProvider>
Expand Down
7 changes: 1 addition & 6 deletions src/components/gridHook/useGridContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const useGridContextMenu = <RowType extends GridBaseRow>({
[contextMenuSelectRow, getSelectedRows, openMenu],
);

// global onclick
return {
openMenu,
cellContextMenu,
Expand All @@ -76,11 +75,7 @@ export const useGridContextMenu = <RowType extends GridBaseRow>({
onClose={() => closeMenu()}
>
{ContextMenu && (
<ContextMenu
selectedRows={selectedRowsRef.current}
colDef={clickedColDefRef.current ?? {}}
close={closeMenu}
/>
<ContextMenu selectedRows={selectedRowsRef.current} colDef={clickedColDefRef.current} close={closeMenu} />
)}
</ControlledMenu>
</>
Expand Down

0 comments on commit 8f2a3ff

Please sign in to comment.