Skip to content

Commit

Permalink
Update MenuSelect prop types to support MUI v5.15.11 types
Browse files Browse the repository at this point in the history
As of
mui/material-ui#39137, MUI's `SelectProps` is
now a `type` and not an `interface`, so we can no longer `extend` it for
our own `MenuSelectProps`. As such, we now make `MenuSelectProps` a
`type` and use `&` syntax to inject additional props. This should
support both MUI < v5.15.11 (where `SelectProps` is an `interface`) and
>= 5.15.11 (where `SelectProps` is a `type`).
  • Loading branch information
sjdemartini committed Jun 28, 2024
1 parent f016a62 commit 7ba1ba9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
8 changes: 5 additions & 3 deletions src/controls/MenuSelectFontFamily.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ export type FontFamilySelectOption = {
label?: ReactNode;
};

export interface MenuSelectFontFamilyProps
extends Except<MenuSelectProps<string>, "value" | "children"> {
export type MenuSelectFontFamilyProps = Except<
MenuSelectProps<string>,
"value" | "children"
> & {
/**
* Provide the list of font families to show as options.
*/
Expand All @@ -56,7 +58,7 @@ export interface MenuSelectFontFamilyProps
* default shows "Font".
*/
emptyLabel?: React.ReactNode;
}
};

const useStyles = makeStyles({ name: { MenuSelectFontFamily } })({
selectInput: {
Expand Down
8 changes: 5 additions & 3 deletions src/controls/MenuSelectFontSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export type FontSizeSelectOptionObject = {
*/
export type FontSizeSelectOption = string | FontSizeSelectOptionObject;

export interface MenuSelectFontSizeProps
extends Except<MenuSelectProps<string>, "value" | "children"> {
export type MenuSelectFontSizeProps = Except<
MenuSelectProps<string>,
"value" | "children"
> & {
/**
* Override the list of the size option strings shown in the dropdown.
*/
Expand Down Expand Up @@ -66,7 +68,7 @@ export interface MenuSelectFontSizeProps
emptyLabel?: React.ReactNode;
/** @deprecated Use `emptyLabel` prop instead. */
emptyValue?: React.ReactNode;
}
};

const useStyles = makeStyles({ name: { MenuSelectFontSize } })({
selectInput: {
Expand Down
11 changes: 5 additions & 6 deletions src/controls/MenuSelectHeading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import { getAttributesForEachSelected } from "../utils/getAttributesForEachSelec
import MenuButtonTooltip from "./MenuButtonTooltip";
import MenuSelect, { type MenuSelectProps } from "./MenuSelect";

export interface MenuSelectHeadingProps
extends Except<
MenuSelectProps<HeadingOptionValue | "">,
"value" | "children"
> {
export type MenuSelectHeadingProps = Except<
MenuSelectProps<HeadingOptionValue | "">,
"value" | "children"
> & {
/**
* Override the default labels for the select options. For any value that
* is omitted in this object, it falls back to the default content.
Expand Down Expand Up @@ -43,7 +42,7 @@ export interface MenuSelectHeadingProps
/** @deprecated Use `labels.empty` instead. */
emptyValue?: React.ReactNode;
};
}
};

const useStyles = makeStyles({ name: { MenuSelectHeading } })((theme) => {
const editorStyles = getEditorStyles(theme);
Expand Down
8 changes: 5 additions & 3 deletions src/controls/MenuSelectTextAlign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export type TextAlignSelectOption = {
shortcutKeys?: MenuButtonTooltipProps["shortcutKeys"];
};

export interface MenuSelectTextAlignProps
extends Except<MenuSelectProps<string>, "children"> {
export type MenuSelectTextAlignProps = Except<
MenuSelectProps<string>,
"children"
> & {
/**
* Override the options shown for text alignment. Use this to change the
* label, icon, tooltip, and shortcut keys shown for each option, and/or the
Expand Down Expand Up @@ -74,7 +76,7 @@ export interface MenuSelectTextAlignProps
* font size, for instance).
*/
emptyLabel?: React.ReactNode;
}
};

const useStyles = makeStyles({ name: { MenuSelectTextAlign } })((theme) => ({
selectInput: {
Expand Down

0 comments on commit 7ba1ba9

Please sign in to comment.