Skip to content

Commit

Permalink
fix: multiselect was not saving values when it had no focus
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrojcm committed Aug 27, 2024
1 parent 3bfa3b0 commit e9beb6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,12 @@ export const MRT_EditCellTextInput = <TData extends MRT_RowData>({
value={value}
{...(selectProps as MRT_MultiSelectProps)}
onBlur={handleBlur}
onChange={(value) => {
onChange={(newValue) => {
(selectProps as MRT_MultiSelectProps).onChange?.(value as any);
setValue(value);
setValue(newValue);
// Save if not in focus, otherwise it will be handled by onBlur
if (document.activeElement === editInputRefs.current[cell.id]) return;
saveInputValueToRowCache(newValue as any);
}}
onClick={(e) => {
e.stopPropagation();
Expand Down
24 changes: 24 additions & 0 deletions packages/mantine-react-table/stories/features/Editing.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,30 @@ export const EditMultiSelectVariant = () => {
);
};

export const EditMultiSelectVariantModal = () => {
const [tableData, setTableData] = useState(data);

const handleSaveRow: MRT_TableOptions<Person>['onEditingRowSave'] = ({
exitEditingMode,
row,
values,
}) => {
tableData[+row.index] = values;
setTableData([...tableData]);
exitEditingMode();
};

return (
<MantineReactTable
columns={multiSelectColumns}
data={tableData}
enableEditing
enableRowActions
onEditingRowSave={handleSaveRow}
/>
);
};

export const EditSelectVariant = () => {
const [tableData, setTableData] = useState(data);

Expand Down

0 comments on commit e9beb6c

Please sign in to comment.