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

Add <TabbedForm.Tab> and <TabbedShowLayout.Tab> shortcuts #8525

Merged

Conversation

fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Dec 20, 2022

Problem

<Tab> and <FormTab> aren't easy to remember.

Solution

Expose the tab component as a sub component of the tabbed components, just like we do with the <Menu.Item>. This introduces two components:

  • <TabbedForm.Tab>
  • <TabbedShowLayout.Tab>
-import { Show, TabbedShowLayout, Tab, TextField } from 'react-admin';
+import { Show, TabbedShowLayout, TextField } from 'react-admin';
export const UserShow = () => {
    const { permissions } = usePermissions();
    return (
        <Show>
            <TabbedShowLayout>
-               <Tab label="user.form.summary">
+               <TabbedShowLayout.Tab label="user.form.summary">
                    {permissions === 'admin' && <TextField source="id" />}
                    <TextField source="name" />
-               </Tab>
+               </TabbedShowLayout.Tab>
                {permissions === 'admin' &&
-                   <Tab label="user.form.security">
+                   <TabbedShowLayout.Tab label="user.form.security">
                        <TextField source="role" />
-                   </Tab>}
+                   </TabbedShowLayout.Tab>}
            </TabbedShowLayout>
        </Show>
    );
};

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.

2 linter warnings

examples/simple/src/posts/PostShow.tsx Show resolved Hide resolved
examples/simple/src/users/UserShow.tsx Show resolved Hide resolved
@vercel
Copy link

vercel bot commented Dec 20, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-admin 🔄 Building (Inspect) Dec 20, 2022 at 2:47PM (UTC)

@antoinefricker antoinefricker modified the milestones: 4.6.3, 4.7.0 Dec 20, 2022
@antoinefricker antoinefricker merged commit d1ff043 into next Dec 20, 2022
@antoinefricker antoinefricker deleted the Add-TabbedForm.Tab-and-TabbedShowLayout.Tab-shortcuts branch December 20, 2022 15:07
@fzaninotto fzaninotto changed the title Add TabbedForm.Tab and TabbedShowLayout.Tab shortcuts Add <TabbedForm.Tab> and <TabbedShowLayout.Tab> shortcuts Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants