File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed
packages/react/src/components/Toggletip Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -82,6 +82,15 @@ describe('Toggletip', () => {
8282 expect ( container . firstChild ) . not . toHaveClass ( `${ prefix } --popover--open` ) ;
8383 } ) ;
8484
85+ it ( 'should render with custom element using as prop' , ( ) => {
86+ const CustomElement = forwardRef ( ( props , ref ) => (
87+ < div data-testid = "custom-toggletip" ref = { ref } { ...props } />
88+ ) ) ;
89+
90+ render ( < Toggletip as = { CustomElement } > Content</ Toggletip > ) ;
91+ expect ( screen . getByTestId ( 'custom-toggletip' ) ) . toBeInTheDocument ( ) ;
92+ } ) ;
93+
8594 describe ( 'Component API' , ( ) => {
8695 it ( 'should support custom elements with the `as` prop' , ( ) => {
8796 const CustomComponent = forwardRef ( ( props , ref ) => {
Original file line number Diff line number Diff line change 66 */
77
88import cx from 'classnames' ;
9- import PropTypes from 'prop-types' ;
9+ import PropTypes , { WeakValidationMap } from 'prop-types' ;
1010import React , {
1111 type ElementType ,
1212 useContext ,
@@ -23,6 +23,7 @@ import { useWindowEvent } from '../../internal/useEvent';
2323import { useId } from '../../internal/useId' ;
2424import { usePrefix } from '../../internal/usePrefix' ;
2525import { PolymorphicProps } from '../../types/common' ;
26+ import { PolymorphicComponentPropWithRef } from '../../internal/PolymorphicProps' ;
2627
2728type ToggletipLabelProps < E extends ElementType > = {
2829 as ?: E ;
@@ -84,16 +85,18 @@ function useToggletip() {
8485 return useContext ( ToggletipContext ) ;
8586}
8687
87- export interface ToggletipProps < E extends ElementType > {
88+ export interface ToggletipBaseProps {
8889 align ?: PopoverAlignment ;
8990 alignmentAxisOffset ?: number ;
90- as ?: E ;
9191 autoAlign ?: boolean ;
9292 className ?: string ;
9393 children ?: ReactNode ;
9494 defaultOpen ?: boolean ;
9595}
9696
97+ export type ToggletipProps < T extends ElementType > =
98+ PolymorphicComponentPropWithRef < T , ToggletipBaseProps > ;
99+
97100/**
98101 * Used as a container for the button and content of a toggletip. This component
99102 * is responsible for coordinating between interactions with the button and the
You can’t perform that action at this time.
0 commit comments