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

[core] Fix render prop types #1213

Merged
merged 5 commits into from
Dec 23, 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
6 changes: 6 additions & 0 deletions packages/react/src/tooltip/trigger/TooltipTrigger.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type * as React from 'react';
import { Tooltip } from '@base-ui-components/react/tooltip';

// `props: any` will error
<Tooltip.Trigger render={(props) => <button type="button" {...props} />} />;
<Tooltip.Trigger render={(props) => <input {...props} />} />;
6 changes: 5 additions & 1 deletion packages/react/src/tooltip/trigger/TooltipTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ namespace TooltipTrigger {
open: boolean;
}

export interface Props extends BaseUIComponentProps<any, State> {}
export interface Props extends BaseUIComponentProps<'div', State> {}
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 expect here people to always need to cast if they use different element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The render prop's props parameter is actually loosely typed in order to allow you to compose different tags.

We need to ensure we document when a tag can't be replaced if we aren't polyfilling native behavior (e.g. if it relies in a specific tag's native props in order to work, like <button> being replaced with a <span>, but internally is not using useButton() to keep it accessible).

We could actually remove the first tag type since it serves no purpose in this case

Copy link
Member

Choose a reason for hiding this comment

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

Let's see if this will be enough, if we see more issues around this we can revisit it.

}

TooltipTrigger.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the TypeScript types and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* @ignore
*/
children: PropTypes.node,
/**
* CSS class applied to the element, or a function that
* returns a class based on the component’s state.
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type ComponentRenderFn<Props, State> = (
export type BaseUIComponentProps<
ElementType extends React.ElementType,
State,
RenderFunctionProps = React.HTMLAttributes<any>,
RenderFunctionProps = GenericHTMLProps,
> = Omit<WithBaseUIEvent<React.ComponentPropsWithoutRef<ElementType>>, 'className'> & {
/**
* CSS class applied to the element, or a function that
Expand Down
Loading