@@ -13,6 +13,11 @@ import { useEuiMemoizedStyles } from '../../../services';
13
13
import { EuiButtonEmpty , type EuiButtonEmptyProps } from '../../button' ;
14
14
import { EuiFieldTextProps } from '../field_text' ;
15
15
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' ;
16
21
17
22
export type EuiFormControlButtonInputProps = {
18
23
/**
@@ -50,10 +55,13 @@ export const EuiFormControlButton: FunctionComponent<
50
55
textProps : _textProps ,
51
56
compressed,
52
57
isInvalid = false ,
58
+ href,
59
+ rel, // required by our local href-with-rel eslint rule
53
60
...rest
54
61
} ) => {
55
- const styles = useEuiMemoizedStyles ( euiFormControlButtonStyles ) ;
62
+ const [ buttonTextRef , innerText ] = useInnerText ( ) ;
56
63
64
+ const styles = useEuiMemoizedStyles ( euiFormControlButtonStyles ) ;
57
65
const classes = classNames ( 'euiFormControlButton' , className ) ;
58
66
59
67
const cssStyles = [
@@ -83,16 +91,33 @@ export const EuiFormControlButton: FunctionComponent<
83
91
const content = isValidElement ( children ) ? children : < span > { children } </ span > ;
84
92
const hasText = value || placeholder ;
85
93
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
+
86
107
return (
87
108
< EuiButtonEmpty
88
109
css = { cssStyles }
89
110
className = { classes }
90
111
contentProps = { contentProps }
91
112
textProps = { false }
92
113
color = "text"
93
- { ...( rest as EuiButtonEmptyProps ) }
114
+ { ...restProps }
94
115
>
95
- { hasText && < span { ...customTextProps } > { value || placeholder } </ span > }
116
+ { hasText && (
117
+ < span { ...customTextProps } ref = { buttonTextRef } >
118
+ { value || placeholder }
119
+ </ span >
120
+ ) }
96
121
{ hasText && content && ' ' }
97
122
{ content }
98
123
</ EuiButtonEmpty >
0 commit comments