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

[UseTabPanel] Add explicit return type #36053

Merged
merged 3 commits into from
Feb 10, 2023
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 docs/pages/base/api/use-tab-panel.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
{
"parameters": {},
"returnValue": {},
"parameters": {
"value": {
"type": {
"name": "number | string",
"description": "The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected."
},
"required": true
}
},
"returnValue": {
"getRootProps": {
"type": {
"name": "() => {\n 'aria-labelledby': string | undefined\n hidden: boolean\n id: string | undefined\n}",
"description": "Resolver for the root slot's props."
},
"required": true
},
"hidden": {
"type": {
"name": "boolean",
"description": "If `true`, it indicates that the tab panel will be hidden."
},
"default": "false",
"required": true
}
},
"name": "useTabPanel",
"filename": "/packages/mui-base/src/TabPanelUnstyled/useTabPanel.ts",
"demos": "<ul><li><a href=\"/base/react-tabs/#hooks\">Unstyled Tabs</a></li></ul>"
Expand Down
11 changes: 10 additions & 1 deletion docs/translations/api-docs/use-tab-panel/use-tab-panel.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{ "hookDescription": "", "parametersDescriptions": {}, "returnValueDescriptions": {} }
{
"hookDescription": "",
"parametersDescriptions": {
"value": "The value of the TabPanel. It will be shown when the Tab with the corresponding value is selected."
},
"returnValueDescriptions": {
"getRootProps": "Resolver for the root slot's props.",
"hidden": "If <code>true</code>, it indicates that the tab panel will be hidden."
}
}
1 change: 1 addition & 0 deletions packages/mui-base/src/TabPanelUnstyled/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { default as tabPanelUnstyledClasses } from './tabPanelUnstyledClasses';
export * from './tabPanelUnstyledClasses';

export { default as useTabPanel } from './useTabPanel';
export * from './useTabPanel.types';
4 changes: 2 additions & 2 deletions packages/mui-base/src/TabPanelUnstyled/useTabPanel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTabContext, getPanelId, getTabId } from '../TabsUnstyled';
import { UseTabPanelParameters } from './useTabPanel.types';
import { UseTabPanelParameters, UseTabPanelReturnValue } from './useTabPanel.types';
/**
*
* Demos:
Expand All @@ -10,7 +10,7 @@ import { UseTabPanelParameters } from './useTabPanel.types';
*
* - [useTabPanel API](https://mui.com/base/api/use-tab-panel/)
*/
function useTabPanel(parameters: UseTabPanelParameters) {
function useTabPanel(parameters: UseTabPanelParameters): UseTabPanelReturnValue {
const { value } = parameters;

const context = useTabContext();
Expand Down
17 changes: 17 additions & 0 deletions packages/mui-base/src/TabPanelUnstyled/useTabPanel.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@ export interface UseTabPanelRootSlotProps {
hidden?: boolean;
id?: string;
}

export interface UseTabPanelReturnValue {
/**
* If `true`, it indicates that the tab panel will be hidden.
* @default false
*/
hidden: boolean;
/**
* Resolver for the root slot's props.
* @returns props that should be spread on the root slot
*/
getRootProps: () => {
'aria-labelledby': string | undefined;
hidden: boolean;
id: string | undefined;
};
}