Skip to content

Add <InPlaceEditor> for edit-in-place #10690

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

Merged
merged 16 commits into from
Apr 29, 2025
Merged

Add <InPlaceEditor> for edit-in-place #10690

merged 16 commits into from
Apr 29, 2025

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Apr 22, 2025

Problem

To edit a value from a record, users have to leave the current screen to go to an Edit view (or use EditInDialog, but they will also lose context).

Solution

<InPlaceEditor> renders a field from the current record. On click, it switches to an editable state, allowing the user to change the value directly.

InPlaceEditor.mp4

Use this component to let users edit parts of a record directly in the list or detail view. It is useful for quick edits without navigating to a separate edit page.

import { Show, InPlaceEditor } from 'react-admin';
import { Stack, Box, Typography } from '@mui/material';

const CustomerShow = () => (
    <Show>
        <Stack direction="row" spacing={2}>
            <AvatarField />
            <CustomerActions />
            <Box sx={{ display: 'flex', justifyContent: 'center' }}>
                <Typography>Phone</Typography>
                <InPlaceEditor source="phone" />
            </Box>
            <Box sx={{ display: 'flex', justifyContent: 'center' }}>
                <Typography>Email</Typography>
                <InPlaceEditor source="email" />
            </Box>
            ...
        </Stack>
    </Show>
);

The field changes color on hover, to indicate that it is editable. The user can cancel the edit by pressing Escape. The field is saved automatically when the user clicks outside of it or presses Enter. While it is being saved, the field is disabled and a loading spinner is shown. If the save fails, an error message is displayed and the original value is restored.

This component can even help replace the <EditableDatagrid>:

InPlaceEditorDataTable.mov

How To Test

http://localhost:9010/?path=/story/ra-ui-materialui-input-inplaceeditor--basic

Additional Checks

  • The PR targets master for a bugfix or a documentation fix, or next for a feature
  • The PR includes unit tests (if not possible, describe why)
  • The PR includes one or several stories (if not possible, describe why)
  • The documentation is up to date
  • Make the doc discoverable by adding links to it

@fzaninotto fzaninotto added RFR Ready For Review and removed WIP Work In Progress labels Apr 28, 2025
@fzaninotto
Copy link
Member Author

Switching to RFR

@fzaninotto fzaninotto changed the title Add In place editor Add <InPlaceEditor> for edit-in-place Apr 28, 2025
Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that this new component works very well and the UX is 👌

@fzaninotto
Copy link
Member Author

Thanks for the great review, I've taken most of your comments into account and added my comments where I disagree.

@slax57 slax57 added this to the 5.8.0 milestone Apr 29, 2025
@slax57 slax57 merged commit 7a1c2b8 into next Apr 29, 2025
16 checks passed
@slax57 slax57 deleted the In-Place-Editor branch April 29, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Development

Successfully merging this pull request may close these issues.

2 participants