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

HStack, VStack: Stop passing invalid props #59416

Merged
merged 5 commits into from
Feb 28, 2024
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug Fix

- `Tooltip`: Explicitly set system font to avoid CSS bleed ([#59307](https://github.com/WordPress/gutenberg/pull/59307)).
- `HStack`, `VStack`: Stop passing invalid props to underlying element ([#59416](https://github.com/WordPress/gutenberg/pull/59416)).
- `Button`: Fix focus outline in disabled primary variant ([#59391](https://github.com/WordPress/gutenberg/pull/59391)).

### Internal
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/flex/flex/hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import type { FlexProps } from '../types';

function useDeprecatedProps(
props: WordPressComponentProps< FlexProps, 'div' >
): WordPressComponentProps< FlexProps, 'div' > {
): Omit< typeof props, 'isReversed' > {
Copy link
Member Author

Choose a reason for hiding this comment

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

This return type was wrong because it wasn't omitting the deprecated isReversed prop, which is specifically being omitted in this hook. It wasn't causing a TS error per se, but it was making it look like useFlex could return another invalid prop (isReversed) in addition to isColumn.

const { isReversed, ...otherProps } = props;

if ( typeof isReversed !== 'undefined' ) {
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/h-stack/hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export function useHStack( props: WordPressComponentProps< Props, 'div' > ) {
gap: spacing,
};

const flexProps = useFlex( propsForFlex );
// Omit `isColumn` because it's not used in HStack.
const { isColumn, ...flexProps } = useFlex( propsForFlex );

return flexProps;
}
10 changes: 10 additions & 0 deletions packages/components/src/h-stack/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ describe( 'props', () => {
);
expect( container ).toMatchSnapshot();
} );

test( 'should not pass through invalid props to the `as` component', () => {
const AsComponent = ( props: JSX.IntrinsicElements[ 'div' ] ) => {
return <div { ...props } />;
};

render( <HStack as={ AsComponent }>foobar</HStack> );

expect( console ).not.toHaveErrored();
} );
} );
10 changes: 10 additions & 0 deletions packages/components/src/v-stack/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ describe( 'props', () => {
);
expect( container ).toMatchSnapshot();
} );

test( 'should not pass through invalid props to the `as` component', () => {
const AsComponent = ( props: JSX.IntrinsicElements[ 'div' ] ) => {
return <div { ...props } />;
};

render( <VStack as={ AsComponent }>foobar</VStack> );

expect( console ).not.toHaveErrored();
} );
} );
Loading