Skip to content

Commit ba522fc

Browse files
committed
refactor: pass value prop for button variant
1 parent b577324 commit ba522fc

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

packages/eui/src/components/button/button_empty/button_empty.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export interface CommonEuiButtonEmptyProps
8484
contentProps?: CommonProps & EuiButtonDisplayContentType;
8585
}
8686

87-
type EuiButtonEmptyPropsForAnchor = PropsForAnchor<CommonEuiButtonEmptyProps>;
87+
export type EuiButtonEmptyPropsForAnchor =
88+
PropsForAnchor<CommonEuiButtonEmptyProps>;
8889

8990
export type EuiButtonEmptyPropsForButton =
9091
PropsForButton<CommonEuiButtonEmptyProps>;

packages/eui/src/components/form/form_control_button/__snapshots__/form_control_button.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ exports[`EuiButtonEmpty is rendered 1`] = `
66
class="euiButtonEmpty euiFormControlButton testClass1 testClass2 emotion-euiButtonDisplay-euiButtonEmpty-m-empty-text-euiFormControlButton-euiTestCss"
77
data-test-subj="test subject string"
88
type="button"
9+
value="Button value"
910
>
1011
<span
1112
class="euiButtonEmpty__content emotion-euiButtonDisplayContent-euiFormControlButton__content"

packages/eui/src/components/form/form_control_button/form_control_button.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import { useEuiMemoizedStyles } from '../../../services';
1313
import { EuiButtonEmpty, type EuiButtonEmptyProps } from '../../button';
1414
import { EuiFieldTextProps } from '../field_text';
1515
import { euiFormControlButtonStyles } from './form_control_button.styles';
16+
import { useInnerText } from '../../inner_text';
17+
import {
18+
EuiButtonEmptyPropsForAnchor,
19+
EuiButtonEmptyPropsForButton,
20+
} from '../../button/button_empty/button_empty';
1621

1722
export type EuiFormControlButtonInputProps = {
1823
/**
@@ -50,10 +55,13 @@ export const EuiFormControlButton: FunctionComponent<
5055
textProps: _textProps,
5156
compressed,
5257
isInvalid = false,
58+
href,
59+
rel, // required by our local href-with-rel eslint rule
5360
...rest
5461
}) => {
55-
const styles = useEuiMemoizedStyles(euiFormControlButtonStyles);
62+
const [buttonTextRef, innerText] = useInnerText();
5663

64+
const styles = useEuiMemoizedStyles(euiFormControlButtonStyles);
5765
const classes = classNames('euiFormControlButton', className);
5866

5967
const cssStyles = [
@@ -83,16 +91,33 @@ export const EuiFormControlButton: FunctionComponent<
8391
const content = isValidElement(children) ? children : <span>{children}</span>;
8492
const hasText = value || placeholder;
8593

94+
const linkProps = {
95+
href,
96+
rel,
97+
...rest,
98+
} as EuiButtonEmptyPropsForAnchor;
99+
100+
const buttonProps = {
101+
value: value ? innerText ?? '' : undefined,
102+
...rest,
103+
} as EuiButtonEmptyPropsForButton;
104+
105+
const restProps = href ? linkProps : buttonProps;
106+
86107
return (
87108
<EuiButtonEmpty
88109
css={cssStyles}
89110
className={classes}
90111
contentProps={contentProps}
91112
textProps={false}
92113
color="text"
93-
{...(rest as EuiButtonEmptyProps)}
114+
{...restProps}
94115
>
95-
{hasText && <span {...customTextProps}>{value || placeholder}</span>}
116+
{hasText && (
117+
<span {...customTextProps} ref={buttonTextRef}>
118+
{value || placeholder}
119+
</span>
120+
)}
96121
{hasText && content && ' '}
97122
{content}
98123
</EuiButtonEmpty>

0 commit comments

Comments
 (0)