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

[SelectUnstyled] Improve exported types #30895

Merged
merged 8 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/mui-base/src/ListboxUnstyled/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,5 @@ export type UseListboxProps<TOption> =
export interface OptionState {
disabled: boolean;
highlighted: boolean;
index: number;
// option: TOption;
selected: boolean;
}
2 changes: 0 additions & 2 deletions packages/mui-base/src/ListboxUnstyled/useListbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ export default function useListbox<TOption>(props: UseListboxProps<TOption>) {
const disabled = isOptionDisabled(option, index);

return {
index,
option,
selected,
disabled,
highlighted: highlightedIndex === index,
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/OptionUnstyled/OptionUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
import { unstable_useForkRef as useForkRef } from '@mui/utils';
import { OptionState } from '../ListboxUnstyled';
import composeClasses from '../composeClasses';
import OptionUnstyledProps from './OptionUnstyledProps';
import OptionUnstyledProps, { OptionUnstyledOwnerState } from './OptionUnstyledProps';
import { SelectUnstyledContext } from '../SelectUnstyled/SelectUnstyledContext';
import { getOptionUnstyledUtilityClass } from './optionUnstyledClasses';
import appendOwnerState from '../utils/appendOwnerState';
Expand Down Expand Up @@ -53,7 +53,7 @@ const OptionUnstyled = React.forwardRef(function OptionUnstyled<TValue>(
const optionState = selectContext.getOptionState(selectOption);
const optionProps = selectContext.getOptionProps(selectOption);

const ownerState = {
const ownerState: OptionUnstyledOwnerState<TValue> = {
...props,
...optionState,
};
Expand Down
3 changes: 3 additions & 0 deletions packages/mui-base/src/OptionUnstyled/OptionUnstyledProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { OptionState } from '../ListboxUnstyled';

export interface OptionUnstyledComponentsPropsOverrides {}

Expand Down Expand Up @@ -37,3 +38,5 @@ export default interface OptionUnstyledProps<TValue> {
root?: React.ComponentPropsWithRef<'li'> & OptionUnstyledComponentsPropsOverrides;
};
}

export type OptionUnstyledOwnerState<TValue> = OptionUnstyledProps<TValue> & OptionState;
22 changes: 22 additions & 0 deletions packages/mui-base/src/SelectUnstyled/SelectUnstyled.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import { SelectUnstyled } from '@mui/base';

const SelectUnstyledComponentsPropsOverridesTest = (
<SelectUnstyled
componentsProps={{
root: {
// @ts-expect-error - requires module augmentation
Copy link
Member

Choose a reason for hiding this comment

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

Do we have test for the module augmentation?

Copy link
Member Author

Choose a reason for hiding this comment

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

Now we do 😊

Copy link
Member

Choose a reason for hiding this comment

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

Awesomeness :D

size: 'red',
className: 'test',
},
popper: {
className: 'popper',
disablePortal: true,
},
listbox: {
className: 'listbox',
onMouseOver: () => {},
},
}}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface SelectUnstyledCommonProps {
componentsProps?: {
root?: React.ComponentPropsWithRef<'button'> & SelectUnstyledComponentsPropsOverrides;
listbox?: React.ComponentPropsWithRef<'ul'> & SelectUnstyledComponentsPropsOverrides;
popper?: React.ComponentPropsWithRef<typeof PopperUnstyled> &
popper?: Partial<React.ComponentPropsWithRef<typeof PopperUnstyled>> &
Copy link
Member

Choose a reason for hiding this comment

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

Why is Partial required here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Popper requires an open prop, but it's not necessary to provide it here in componentsProps.

Copy link
Member

Choose a reason for hiding this comment

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

Alright, could we leave an comment for it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, it's done!

SelectUnstyledComponentsPropsOverrides;
};
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import { SelectUnstyled } from '@mui/base';

declare module '@mui/base' {
interface SelectUnstyledComponentsPropsOverrides {
variant?: 'one' | 'two';
}
}

<SelectUnstyled componentsProps={{ root: { variant: 'one' } }} />;

// @ts-expect-error unknown variant
<SelectUnstyled componentsProps={{ root: { variant: 'three' } }} />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../../../../tsconfig",
"files": ["selectUnstyledComponentsProps.spec.tsx"]
}