Skip to content

Commit bb8cca0

Browse files
committed
[EuiButtonEmpty] Allow disabling the text wrapper
(setup for datagrid button cleanup) - `textProps &&` is required now for typing, to avoid `false` shenanigans
1 parent a987085 commit bb8cca0

6 files changed

Lines changed: 43 additions & 13 deletions

File tree

src/components/button/button_display/_button_display_content.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ describe('EuiButtonDisplayContent', () => {
9898
expect(container.querySelector('.eui-textTruncate')).toBeTruthy();
9999
});
100100

101+
it('does not render a text span wrapper if textProps is explicitly set to false', () => {
102+
const { container } = render(
103+
<EuiButtonDisplayContent textProps={false}>
104+
Text
105+
</EuiButtonDisplayContent>
106+
);
107+
108+
expect(container.querySelector('.eui-textTruncate')).toBeFalsy();
109+
});
110+
101111
it('does not render a text span wrapper if custom child with no textProps are passed', () => {
102112
const { getByTestSubject, container } = render(
103113
<EuiButtonDisplayContent>

src/components/button/button_display/_button_display_content.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ export interface EuiButtonDisplayContentProps extends CommonProps {
3737
iconSide?: ButtonContentIconSide;
3838
isLoading?: boolean;
3939
/**
40-
* Object of props passed to the <span/> wrapping the content's text/children only (not icon)
40+
* Object of props passed to the `<span>` wrapping the content's text/children only (not icon)
41+
*
42+
* This span wrapper can be removed by passing `textProps={false}`.
4143
*/
42-
textProps?: HTMLAttributes<HTMLSpanElement> &
43-
CommonProps & {
44-
ref?: Ref<HTMLSpanElement>;
45-
'data-text'?: string;
46-
};
44+
textProps?:
45+
| (HTMLAttributes<HTMLSpanElement> &
46+
CommonProps & {
47+
ref?: Ref<HTMLSpanElement>;
48+
'data-text'?: string;
49+
})
50+
| false;
4751
iconSize?: ButtonContentIconSize;
4852
isDisabled?: boolean;
4953
}
@@ -90,11 +94,13 @@ export const EuiButtonDisplayContent: FunctionComponent<
9094
}
9195

9296
const isText = typeof children === 'string';
97+
const doNotRenderTextWrapper = textProps === false;
98+
const renderTextWrapper = (isText || textProps) && !doNotRenderTextWrapper;
9399

94100
return (
95101
<span css={cssStyles} {...contentProps}>
96102
{iconSide === 'left' && icon}
97-
{isText || textProps ? (
103+
{renderTextWrapper ? (
98104
<span
99105
{...textProps}
100106
className={classNames('eui-textTruncate', textProps?.className)}

src/components/button/button_empty/button_empty.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,15 @@ describe('EuiButtonEmpty', () => {
167167

168168
expect(container.firstChild).toMatchSnapshot();
169169
});
170+
171+
it('does not render the text wrapper when textProps is set to false', () => {
172+
const { container } = render(
173+
<EuiButtonEmpty textProps={false}>Content</EuiButtonEmpty>
174+
);
175+
176+
expect(
177+
container.querySelector('.euiButtonEmpty__text')
178+
).not.toBeInTheDocument();
179+
});
170180
});
171181
});

src/components/button/button_empty/button_empty.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export interface CommonEuiButtonEmptyProps
7272
type?: 'button' | 'submit';
7373
buttonRef?: Ref<HTMLButtonElement | HTMLAnchorElement>;
7474
/**
75-
* Object of props passed to the <span/> wrapping the button's content
75+
* Object of props passed to the `<span>` wrapping the button's content
7676
*/
7777
contentProps?: CommonProps & EuiButtonDisplayContentType;
7878
}
@@ -139,7 +139,7 @@ export const EuiButtonEmpty: FunctionComponent<EuiButtonEmptyProps> = ({
139139

140140
const textClassNames = classNames(
141141
'euiButtonEmpty__text',
142-
textProps?.className
142+
textProps && textProps.className
143143
);
144144

145145
const innerNode = (
@@ -149,7 +149,11 @@ export const EuiButtonEmpty: FunctionComponent<EuiButtonEmptyProps> = ({
149149
iconType={iconType}
150150
iconSide={iconSide}
151151
iconSize={size === 'xs' ? 's' : iconSize}
152-
textProps={{ ...textProps, className: textClassNames }}
152+
textProps={
153+
textProps === false
154+
? false
155+
: { ...textProps, className: textClassNames }
156+
}
153157
{...{ ...contentProps, className: contentClassNames }}
154158
>
155159
{children}

src/components/date_picker/super_date_picker/super_update_button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class EuiSuperUpdateButton extends Component<
185185
...restTextProps,
186186
className: classNames(
187187
'euiScreenReaderOnly',
188-
restTextProps?.className
188+
restTextProps && restTextProps.className
189189
),
190190
}}
191191
{...rest}

src/components/filter_group/filter_button.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
119119
const buttonTextClassNames = classNames(
120120
'euiFilterButton__text',
121121
{ 'euiFilterButton__text-hasNotification': showBadge },
122-
textProps?.className
122+
textProps && textProps.className
123123
);
124124

125125
const badgeContent = showBadge && (
@@ -171,7 +171,7 @@ export const EuiFilterButton: FunctionComponent<EuiFilterButtonProps> = ({
171171
css: [
172172
textStyles.euiFilterButton__text,
173173
showBadge && textStyles.hasNotification,
174-
textProps?.css,
174+
textProps && textProps.css,
175175
],
176176
}}
177177
contentProps={{

0 commit comments

Comments
 (0)