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

[TabPanel] Type mismatch between tabContext and tanPanel #44149

Open
blackcow1987 opened this issue Oct 18, 2024 · 0 comments
Open

[TabPanel] Type mismatch between tabContext and tanPanel #44149

blackcow1987 opened this issue Oct 18, 2024 · 0 comments
Assignees
Labels
component: tabs This is the name of the generic UI component, not the React module! package: lab Specific to @mui/lab status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@blackcow1987
Copy link

blackcow1987 commented Oct 18, 2024

Steps to reproduce

According to TabPanel's type definition, value must be a string.

https://github.com/mui/material-ui/blob/v6.1.4/packages/mui-lab/src/TabPanel/TabPanel.d.ts#L24

  /**
   * The `value` of the corresponding `Tab`. Must use the index of the `Tab` when
   * no `value` was passed to `Tab`.
   */
  value: string;
};

But according to TabContext's type definition, value must be a string or number.

https://github.com/mui/material-ui/blob/v6.1.4/packages/mui-lab/src/TabContext/TabContext.d.ts#L16

  /**
   * The value of the currently selected `Tab`.
   */
  value: string | number;
}

When using TabContext, because the currently active tab information is stored in the Context and compared within the TabPanel component, the value ​​of the two components must use the same type.

https://github.com/mui/material-ui/blob/v6.1.4/packages/mui-lab/src/TabPanel/TabPanel.js#L50

  const context = useTabContext();
  if (context === null) {
    throw new TypeError('No TabContext provided');
  }
  const id = getPanelId(context, value);
  const tabId = getTabId(context, value);

  return (
    <TabPanelRoot
      aria-labelledby={tabId}
      className={clsx(classes.root, className)}
      hidden={value !== context.value}

Current behavior

The value ​​of TabContext and TabPanel are using different types.

Expected behavior

The value ​​of TabContext and TabPanel must use the same type.

Context

No response

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Search keywords: TabPanel

@blackcow1987 blackcow1987 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 18, 2024
@zannager zannager added component: tabs This is the name of the generic UI component, not the React module! package: lab Specific to @mui/lab labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module! package: lab Specific to @mui/lab status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants