diff --git a/CHANGELOG.md b/CHANGELOG.md index 5621fb0fa2e..d3c451c22f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Fixed visual bug in drag&drop sections when nested in an popover ([#4590](https://github.com/elastic/eui/pull/4590)) - Fixed an errant export of `EuiSideNavProps` type from JS code ([#4604](https://github.com/elastic/eui/pull/4604)) - Fixed misaligned `EuiComboBox` options list ([#4607](https://github.com/elastic/eui/pull/4607)) +- Fixed missing `forwardRef` on `EuiHeaderSectionItemButton` ([#4631](https://github.com/elastic/eui/pull/4631)) ## [`31.9.1`](https://github.com/elastic/eui/tree/v31.9.1) diff --git a/src/components/button/button_empty/button_empty.tsx b/src/components/button/button_empty/button_empty.tsx index c89dae37dcf..32160808e93 100644 --- a/src/components/button/button_empty/button_empty.tsx +++ b/src/components/button/button_empty/button_empty.tsx @@ -17,7 +17,7 @@ * under the License. */ -import React, { FunctionComponent } from 'react'; +import React, { FunctionComponent, Ref } from 'react'; import classNames from 'classnames'; import { @@ -76,7 +76,9 @@ export const FLUSH_TYPES = keysOf(flushTypeToClassNameMap); * Extends EuiButtonContentProps which provides * `iconType`, `iconSide`, and `textProps` */ -interface CommonEuiButtonEmptyProps extends EuiButtonContentProps, CommonProps { +export interface CommonEuiButtonEmptyProps + extends EuiButtonContentProps, + CommonProps { /** * Any of our named colors */ @@ -103,7 +105,7 @@ interface CommonEuiButtonEmptyProps extends EuiButtonContentProps, CommonProps { target?: string; rel?: string; type?: 'button' | 'submit'; - buttonRef?: (ref: HTMLButtonElement | HTMLAnchorElement | null) => void; + buttonRef?: Ref; /** * Object of props passed to the wrapping the button's content */ @@ -192,7 +194,7 @@ export const EuiButtonEmpty: FunctionComponent = ({ href={href} target={target} rel={secureRel} - ref={buttonRef} + ref={buttonRef as Ref} {...(rest as EuiButtonEmptyPropsForAnchor)}> {innerNode} @@ -204,7 +206,7 @@ export const EuiButtonEmpty: FunctionComponent = ({ disabled={buttonIsDisabled} className={classes} type={type} - ref={buttonRef} + ref={buttonRef as Ref} aria-pressed={isSelected} {...(rest as EuiButtonEmptyPropsForButton)}> {innerNode} diff --git a/src/components/header/header_section/header_section_item_button.tsx b/src/components/header/header_section/header_section_item_button.tsx index bc45d8a7839..e94bba4adda 100644 --- a/src/components/header/header_section/header_section_item_button.tsx +++ b/src/components/header/header_section/header_section_item_button.tsx @@ -17,7 +17,7 @@ * under the License. */ -import React, { FunctionComponent } from 'react'; +import React, { forwardRef, PropsWithChildren } from 'react'; import classNames from 'classnames'; import { @@ -39,43 +39,55 @@ export type EuiHeaderSectionItemButtonProps = EuiButtonEmptyProps & { notificationColor?: EuiNotificationBadgeProps['color']; }; -export const EuiHeaderSectionItemButton: FunctionComponent = ({ - children, - className, - notification, - notificationColor = 'accent', - ...rest -}) => { - const classes = classNames('euiHeaderSectionItem__button', className); +export const EuiHeaderSectionItemButton = forwardRef< + HTMLButtonElement | HTMLAnchorElement, + PropsWithChildren +>( + ( + { + children, + className, + notification, + notificationColor = 'accent', + ...rest + }, + ref + ) => { + const classes = classNames('euiHeaderSectionItem__button', className); - let notificationBadge; - if (notification) { - if (notification === true) { - notificationBadge = ( - - ); - } else { - notificationBadge = ( - - {notification} - - ); + let notificationBadge; + if (notification) { + if (notification === true) { + notificationBadge = ( + + ); + } else { + notificationBadge = ( + + {notification} + + ); + } } - } - return ( - - {children} - {notificationBadge} - - ); -}; + return ( + + {children} + {notificationBadge} + + ); + } +); EuiHeaderSectionItemButton.displayName = 'EuiHeaderSectionItemButton';