diff --git a/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap b/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap index dc64e847a86..defa590e67b 100644 --- a/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap +++ b/src/components/button/button_group/__snapshots__/button_group.test.tsx.snap @@ -20,6 +20,7 @@ exports[`EuiButtonGroup button props buttonSize compressed is rendered for multi aria-pressed="false" class="euiButtonGroupButton testClass1 testClass2 emotion-euiButtonDisplay-s-defaultMinWidth-euiButtonGroupButton-empty-text-euiTestCss" data-test-subj="test subject string" + title="Option one" type="button" > { { id: 'buttonWithTooltip', label: 'Option 4', + toolTipContent: 'I am a tooltip', }, ]} /> ); fireEvent.mouseOver(getByTestSubject('buttonWithTooltip')); await waitForEuiToolTipVisible(); - expect(getByRole('tooltip')).toHaveTextContent('Option 4'); + expect(getByRole('tooltip')).toHaveTextContent('I am a tooltip'); }); it('shows a tooltip on focus', async () => { @@ -252,17 +253,18 @@ describe('EuiButtonGroup', () => { { id: 'buttonWithTooltip', label: 'Option 4', + toolTipContent: 'I am a tooltip', }, ]} /> ); fireEvent.focus(getByTestSubject('buttonWithTooltip')); await waitForEuiToolTipVisible(); - expect(getByRole('tooltip')).toHaveTextContent('Option 4'); + expect(getByRole('tooltip')).toHaveTextContent('I am a tooltip'); }); - it('allows overriding the default title', async () => { - const { getByTestSubject, getByRole } = render( + it('should automatically add a title attribute with the provided label if no tooltip is provided', () => { + const { getByTestSubject } = render( { { id: 'buttonWithTooltip', label: 'Option 4', - title: 'I am a tooltip', }, ]} /> ); - fireEvent.mouseOver(getByTestSubject('buttonWithTooltip')); - await waitForEuiToolTipVisible(); - expect(getByRole('tooltip')).toHaveTextContent('I am a tooltip'); + expect(getByTestSubject('buttonWithTooltip')).toHaveAttribute( + 'title', + 'Option 4' + ); + }); + + it('should not add a title attribute if a tooltip is provided', () => { + const { getByTestSubject } = render( + + ); + expect(getByTestSubject('buttonWithTooltip')).not.toHaveAttribute( + 'title' + ); }); it('allows customizing the tooltip delay', async () => { @@ -291,7 +313,10 @@ describe('EuiButtonGroup', () => { { id: 'buttonWithTooltip', label: 'Option 4', - title: 'I am a tooltip', + toolTipContent: 'I am a tooltip', + toolTipProps: { + delay: 'long', + }, }, ]} /> @@ -311,8 +336,10 @@ describe('EuiButtonGroup', () => { { id: 'buttonWithTooltip', label: 'Option 4', - title: 'I am a tooltip', - titleDelay: 'regular', + toolTipContent: 'I am a tooltip', + toolTipProps: { + delay: 'regular', + }, }, ]} /> @@ -334,7 +361,7 @@ describe('EuiButtonGroup', () => { { id: 'buttonWithTooltip', label: 'Option 4', - title: 'I am a tooltip', + toolTipContent: 'I am a tooltip', }, ]} /> @@ -355,8 +382,10 @@ describe('EuiButtonGroup', () => { { id: 'buttonWithTooltip', label: 'Option 4', - title: 'I am a tooltip', - titlePosition: 'bottom', + toolTipContent: 'I am a tooltip', + toolTipProps: { + position: 'bottom', + }, }, ]} /> @@ -369,27 +398,6 @@ describe('EuiButtonGroup', () => { ); }); - it('does not show a tooltip for buttons with visible text', async () => { - const { getByTestSubject, queryByRole } = render( - - ); - fireEvent.mouseOver(getByTestSubject('buttonWithTooltip')); - await act(async () => { - await new Promise((resolve) => setTimeout(resolve, 500)); - }); - expect(queryByRole('tooltip')).toBeNull(); - }); - it('hides the tooltip on click until rehovered/refocused', async () => { const { getByTestSubject, queryByRole } = render( { { id: 'buttonWithTooltip', label: 'Option 4', + toolTipContent: 'I am a tooltip', }, ]} /> diff --git a/src/components/button/button_group/button_group.tsx b/src/components/button/button_group/button_group.tsx index f7c375497b3..e20c6677eb0 100644 --- a/src/components/button/button_group/button_group.tsx +++ b/src/components/button/button_group/button_group.tsx @@ -48,19 +48,13 @@ export interface EuiButtonGroupOptionProps */ type?: ButtonHTMLAttributes['type']; /** - * Custom title content for the button, only used if isIconOnly is true + * Custom tooltip content for the button */ - title?: EuiToolTipProps['content']; + toolTipContent?: EuiToolTipProps['content']; /** - * Custom title delay - * @default 'long' + * Custom tooltip props for the button */ - titleDelay?: EuiToolTipProps['delay']; - /** - * Custom title position - * @default 'top' - */ - titlePosition?: EuiToolTipProps['position']; + toolTipProps?: Partial>; } export type EuiButtonGroupProps = CommonProps & { diff --git a/src/components/button/button_group/button_group_button.tsx b/src/components/button/button_group/button_group_button.tsx index 65d65e26039..dd01d0bc29c 100644 --- a/src/components/button/button_group/button_group_button.tsx +++ b/src/components/button/button_group/button_group_button.tsx @@ -55,9 +55,8 @@ export const EuiButtonGroupButton: FunctionComponent = ({ value, // Prevent prop from being spread size, color: _color = 'primary', - title, - titleDelay = 'long', - titlePosition = 'top', + toolTipContent, + toolTipProps, onClick, ...rest }) => { @@ -103,28 +102,35 @@ export const EuiButtonGroupButton: FunctionComponent = ({ * the base width of the button via the `euiTextShift()` method in SASS. */ const [buttonTextRef, innerText] = useInnerText(); - const tooltipRef = useRef(null); + const toolTipRef = useRef(null); const onClickOverride: React.MouseEventHandler = (e) => { // Blur the tooltip so it doesn't stick around after click until rehovered/refocused - tooltipRef.current?.onBlur(); + toolTipRef.current?.onBlur(); onClick(e); }; return ( @@ -139,6 +145,7 @@ export const EuiButtonGroupButton: FunctionComponent = ({ ref: buttonTextRef, 'data-text': innerText, }} + title={toolTipContent ? undefined : innerText} data-test-subj={id} isSelected={isSelected} onClick={onClickOverride}