Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiselect was not saving values when it had no focus #401

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading