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 <FormTab> doesn't highlight selected tab label #7693

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
28 changes: 26 additions & 2 deletions packages/ra-ui-materialui/src/form/FormTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { ReactElement, ReactNode } from 'react';
import PropTypes from 'prop-types';
import { FormGroupContextProvider } from 'ra-core';
import { Stack, StackProps } from '@mui/material';
import { Stack, StackProps, TabProps as MuiTabProps } from '@mui/material';

import { FormTabHeader } from './FormTabHeader';

Expand Down Expand Up @@ -31,6 +31,7 @@ export const FormTab = (props: FormTabProps) => {
className={className}
syncWithLocation={syncWithLocation}
onChange={onChange}
{...sanitizeRestProps(rest)}
/>
);

Expand Down Expand Up @@ -70,7 +71,9 @@ FormTab.propTypes = {
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};

export interface FormTabProps extends StackProps {
export interface FormTabProps
extends Omit<StackProps, 'color'>,
Omit<MuiTabProps, 'children' | 'classes' | 'ref'> {
className?: string;
children?: ReactNode;
contentClassName?: string;
Expand All @@ -87,3 +90,24 @@ export interface FormTabProps extends StackProps {
FormTab.displayName = 'FormTab';

const hiddenStyle = { display: 'none' };

const sanitizeRestProps = ({
classes,
ref,
margin,
...rest
}: Omit<
FormTabProps,
| 'className'
| 'contentClassName'
| 'children'
| 'hidden'
| 'icon'
| 'intent'
| 'label'
| 'onChange'
| 'path'
| 'resource'
| 'syncWithLocation'
| 'value'
>) => rest;
4 changes: 2 additions & 2 deletions packages/ra-ui-materialui/src/form/FormTabHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import { isValidElement, ReactElement } from 'react';
import PropTypes from 'prop-types';
import { Link, useLocation } from 'react-router-dom';
import { Tab as MuiTab } from '@mui/material';
import { Tab as MuiTab, TabProps as MuiTabProps } from '@mui/material';
import clsx from 'clsx';
import { useTranslate, useFormGroup } from 'ra-core';
import { useFormState } from 'react-hook-form';
Expand Down Expand Up @@ -50,7 +50,7 @@ export const FormTabHeader = ({
);
};

interface FormTabHeaderProps {
interface FormTabHeaderProps extends Omit<MuiTabProps, 'children'> {
className?: string;
hidden?: boolean;
icon?: ReactElement;
Expand Down