Skip to content

Commit

Permalink
Add exitEditMode prop to DataEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
iddan committed Sep 23, 2021
1 parent b7bc293 commit 600231c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ActiveCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const ActiveCell: React.FC<Props> = (props) => {
dispatch(Actions.commit(changes)),
[dispatch]
);
const view = React.useCallback(() => {
dispatch(Actions.view());
}, [dispatch]);
const active = useSelector((state) => state.active);
const mode = useSelector((state) => state.mode);
const cell = useSelector((state) =>
Expand Down Expand Up @@ -112,6 +115,7 @@ const ActiveCell: React.FC<Props> = (props) => {
cell={cell}
// @ts-ignore
onChange={handleChange}
exitEditMode={view}
/>
)}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/DataEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const EXAMPLE_PROPS: Types.DataEditorProps = {
column: 0,
cell: EXAMPLE_CELL,
onChange: ON_CHANGE_MOCK,
exitEditMode: jest.fn(),
};

beforeEach(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ export type DataEditorProps<Cell extends CellBase = CellBase> =
DataComponentProps<Cell> & {
/** Callback to be called when the cell's value is changed */
onChange: (cell: Cell) => void;
/** Callback to be called when edit mode should be exited */
exitEditMode: () => void;
};

/** Type of the Spreadsheet DataEditor component */
Expand Down

0 comments on commit 600231c

Please sign in to comment.