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

Menu: use ariakit types #68206

Merged
merged 4 commits into from
Dec 23, 2024
Merged
Changes from 1 commit
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
Next Next commit
Menu: use ariakit types
  • Loading branch information
ciampo committed Dec 22, 2024
commit 22b528a9e0fe35f768d0f7a3e388a76d733c3372
105 changes: 68 additions & 37 deletions packages/components/src/menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import type * as Ariakit from '@ariakit/react';
import type { Placement } from '@floating-ui/react-dom';

export interface MenuContext {
/**
Expand All @@ -19,75 +18,71 @@ export interface MenuProps {
/**
* The contents of the menu (ie. one or more menu items).
*/
children?: React.ReactNode;
children?: Ariakit.MenuProviderProps[ 'children' ];
/**
* The open state of the menu popover when it is initially rendered. Use when
* not wanting to control its open state.
*
* @default false
*/
defaultOpen?: boolean;
defaultOpen?: Ariakit.MenuProviderProps[ 'defaultOpen' ];
/**
* The controlled open state of the menu popover. Must be used in conjunction
* with `onOpenChange`.
*/
open?: boolean;
open?: Ariakit.MenuProviderProps[ 'open' ];
/**
* Event handler called when the open state of the menu popover changes.
*/
onOpenChange?: ( open: boolean ) => void;
onOpenChange?: Ariakit.MenuProviderProps[ 'setOpen' ];
/**
* The placement of the menu popover.
*
* @default 'bottom-start' for root-level menus, 'right-start' for nested menus
*/
placement?: Placement;
placement?: Ariakit.MenuProviderProps[ 'placement' ];
}

export interface MenuPopoverProps {
/**
* The contents of the dropdown.
*/
children?: React.ReactNode;
children?: Ariakit.MenuProps[ 'children' ];
/**
* The modality of the menu popover. When set to true, interaction with
* outside elements will be disabled and only menu content will be visible to
* screen readers.
*
* @default true
*/
modal?: boolean;
modal?: Ariakit.MenuProps[ 'modal' ];
/**
* The distance between the popover and the anchor element.
*
* @default 8 for root-level menus, 16 for nested menus
*/
gutter?: number;
gutter?: Ariakit.MenuProps[ 'gutter' ];
/**
* The skidding of the popover along the anchor element. Can be set to
* negative values to make the popover shift to the opposite side.
*
* @default 0 for root-level menus, -8 for nested menus
*/
shift?: number;
shift?: Ariakit.MenuProps[ 'shift' ];
/**
* Determines whether the menu popover will be hidden when the user presses
* the Escape key.
*
* @default `( event ) => { event.preventDefault(); return true; }`
*/
hideOnEscape?:
| boolean
| ( (
event: KeyboardEvent | React.KeyboardEvent< Element >
) => boolean );
hideOnEscape?: Ariakit.MenuProps[ 'hideOnEscape' ];
}

export interface MenuTriggerButtonProps {
/**
* The contents of the menu trigger button.
*/
children?: React.ReactNode;
children?: Ariakit.MenuButtonProps[ 'children' ];
/**
* Allows the component to be rendered as a different HTML element or React
* component. The value can be a React element or a function that takes in the
Expand Down Expand Up @@ -132,21 +127,21 @@ export interface MenuGroupProps {
* The contents of the menu group (ie. an optional menu group label and one
* or more menu items).
*/
children: React.ReactNode;
children: Ariakit.MenuGroupProps[ 'children' ];
}

export interface MenuGroupLabelProps {
/**
* The contents of the menu group label.
*/
children: React.ReactNode;
children: Ariakit.MenuGroupLabelProps[ 'children' ];
}

export interface MenuItemProps {
/**
* The contents of the menu item.
*/
children: React.ReactNode;
children: Ariakit.MenuItemProps[ 'children' ];
/**
* The contents of the menu item's prefix.
*/
Expand All @@ -160,11 +155,11 @@ export interface MenuItemProps {
*
* @default true
*/
hideOnClick?: boolean;
hideOnClick?: Ariakit.MenuItemProps[ 'hideOnClick' ];
/**
* Determines if the element is disabled.
*/
disabled?: boolean;
disabled?: Ariakit.MenuItemProps[ 'disabled' ];
/**
* Allows the component to be rendered as a different HTML element or React
* component. The value can be a React element or a function that takes in the
Expand All @@ -179,67 +174,103 @@ export interface MenuItemProps {
store?: Ariakit.MenuItemProps[ 'store' ];
}

export interface MenuCheckboxItemProps
extends Omit< MenuItemProps, 'prefix' | 'hideOnClick' > {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the extends syntax so that each component uses the correct ariakit types (ie. Menu.Item uses Ariakit.MenuItemProps, Menu.CheckboxItem uses Ariakit.MenuItemCheckboxProps, and Menu.RadioItem uses Ariakit.MenuItemRadioProps

export interface MenuCheckboxItemProps {
/**
* The contents of the menu item.
*/
children: Ariakit.MenuItemCheckboxProps[ 'children' ];
/**
* The contents of the menu item's suffix.
*/
suffix?: React.ReactNode;
/**
* Whether to hide the menu popover when the menu item is clicked.
*
* @default false
*/
hideOnClick?: boolean;
hideOnClick?: Ariakit.MenuItemCheckboxProps[ 'hideOnClick' ];
/**
* Determines if the element is disabled.
*/
disabled?: Ariakit.MenuItemCheckboxProps[ 'disabled' ];
/**
* Allows the component to be rendered as a different HTML element or React
* component. The value can be a React element or a function that takes in the
* original component props and gives back a React element with the props
* merged.
*/
render?: Ariakit.MenuItemCheckboxProps[ 'render' ];
/**
* The checkbox menu item's name.
*/
name: string;
name: Ariakit.MenuItemCheckboxProps[ 'name' ];
/**
* The checkbox item's value, useful when using multiple checkbox menu items
* associated to the same `name`.
*/
value?: string;
value?: Ariakit.MenuItemCheckboxProps[ 'value' ];
/**
* The controlled checked state of the checkbox menu item.
*/
checked?: boolean;
checked?: Ariakit.MenuItemCheckboxProps[ 'checked' ];
/**
* The checked state of the checkbox menu item when it is initially rendered.
* Use when not wanting to control its checked state.
*/
defaultChecked?: boolean;
defaultChecked?: Ariakit.MenuItemCheckboxProps[ 'defaultChecked' ];
/**
* Event handler called when the checked state of the checkbox menu item changes.
*/
onChange?: ( event: React.ChangeEvent< HTMLInputElement > ) => void;
onChange?: Ariakit.MenuItemCheckboxProps[ 'onChange' ];
}

export interface MenuRadioItemProps
extends Omit< MenuItemProps, 'prefix' | 'hideOnClick' > {
export interface MenuRadioItemProps {
/**
* The contents of the menu item.
*/
children: Ariakit.MenuItemRadioProps[ 'children' ];
/**
* The contents of the menu item's suffix.
*/
suffix?: React.ReactNode;
/**
* Whether to hide the menu popover when the menu item is clicked.
*
* @default false
*/
hideOnClick?: boolean;
hideOnClick?: Ariakit.MenuItemRadioProps[ 'hideOnClick' ];
/**
* Determines if the element is disabled.
*/
disabled?: Ariakit.MenuItemRadioProps[ 'disabled' ];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added an explicit false value for the disabled prop — this is also reflected in the code when destructuring props

/**
* Allows the component to be rendered as a different HTML element or React
* component. The value can be a React element or a function that takes in the
* original component props and gives back a React element with the props
* merged.
*/
render?: Ariakit.MenuItemRadioProps[ 'render' ];
/**
* The radio item's name.
*/
name: string;
name: Ariakit.MenuItemRadioProps[ 'name' ];
/**
* The radio item's value.
*/
value: string | number;
value: Ariakit.MenuItemRadioProps[ 'value' ];
/**
* The controlled checked state of the radio menu item.
*/
checked?: boolean;
checked?: Ariakit.MenuItemRadioProps[ 'checked' ];
/**
* The checked state of the radio menu item when it is initially rendered.
* Use when not wanting to control its checked state.
*/
defaultChecked?: boolean;
defaultChecked?: Ariakit.MenuItemRadioProps[ 'defaultChecked' ];
/**
* Event handler called when the checked radio menu item changes.
*/
onChange?: ( event: React.ChangeEvent< HTMLInputElement > ) => void;
onChange?: Ariakit.MenuItemRadioProps[ 'onChange' ];
}

export interface MenuSeparatorProps {}