Skip to content

Commit

Permalink
Toolbar/ToolbarDropdownMenu Typescript Conversion (#54321)
Browse files Browse the repository at this point in the history
* Converts file to tsx, removes ts-no-check and small spelling fix

* Spelling

* Adds dropdown menu types to toolbar dropdown

* Adds changelog entry

---------

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
  • Loading branch information
margolisj and ciampo authored Sep 11, 2023
1 parent 65bf4f7 commit 0153ccc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Internal

- `Toolbar/ToolbarDropdownMenu `: Convert to TypeScript ([#54321](https://github.com/WordPress/gutenberg/pull/54321)).
- `Composite`: Convert to TypeScript ([#54028](https://github.com/WordPress/gutenberg/pull/54028)).
- `BorderControl`: Refactor unit tests to use `userEvent` ([#54155](https://github.com/WordPress/gutenberg/pull/54155))
- `FocusableIframe`: Convert to TypeScript ([#53979](https://github.com/WordPress/gutenberg/pull/53979)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
// @ts-nocheck

/**
* WordPress dependencies
*/
import { forwardRef, useContext } from '@wordpress/element';

/**
* External dependencies
*/
import type { ForwardedRef } from 'react';

/**
* Internal dependencies
*/
import ToolbarItem from '../toolbar-item';
import ToolbarContext from '../toolbar-context';
import DropdownMenu from '../../dropdown-menu';
import type { DropdownMenuProps } from '../../dropdown-menu/types';

function ToolbarDropdownMenu( props, ref ) {
function ToolbarDropdownMenu(
props: DropdownMenuProps,
ref: ForwardedRef< any >
) {
const accessibleToolbarState = useContext( ToolbarContext );

if ( ! accessibleToolbarState ) {
return <DropdownMenu { ...props } />;
}

// ToobarItem will pass all props to the render prop child, which will pass
// ToolbarItem will pass all props to the render prop child, which will pass
// all props to the toggle of DropdownMenu. This means that ToolbarDropdownMenu
// has the same API as DropdownMenu.
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ui/context/wordpress-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type WordPressComponentProps<
> = P &
// The `children` prop is being explicitly omitted since it is otherwise implicitly added
// by `ComponentPropsWithRef`. The context is that components should require the `children`
// prop explicitely when needed (see https://github.com/WordPress/gutenberg/pull/31817).
// prop explicitly when needed (see https://github.com/WordPress/gutenberg/pull/31817).
Omit< React.ComponentPropsWithoutRef< T >, 'as' | keyof P | 'children' > &
( IsPolymorphic extends true
? {
Expand Down

0 comments on commit 0153ccc

Please sign in to comment.