@@ -40,6 +40,11 @@ import { euiInlineEditReadModeStyles } from './inline_edit_form.styles';
4040export type EuiInlineEditCommonProps = HTMLAttributes < HTMLDivElement > &
4141 CommonProps & {
4242 defaultValue : string ;
43+ /**
44+ * Adds styling to display defaultValue as a placeholder in `readMode`.
45+ * Adds defaultValue as a placeholder on the `editMode` form control and does not populate the value.
46+ */
47+ displayDefaultValueAsPlaceholder ?: boolean ;
4348 /**
4449 * Callback that fires when a user clicks the save button.
4550 * Passes the current edited text value as an argument.
@@ -121,6 +126,7 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
121126 children,
122127 sizes,
123128 defaultValue,
129+ displayDefaultValueAsPlaceholder,
124130 inputAriaLabel,
125131 startWithEditOpen,
126132 readModeProps,
@@ -132,12 +138,17 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
132138} ) => {
133139 const classes = classNames ( 'euiInlineEdit' , className ) ;
134140
141+ const [ renderPlaceholder , setRenderPlaceholder ] = useState (
142+ displayDefaultValueAsPlaceholder
143+ ) ;
144+
135145 const euiTheme = useEuiTheme ( ) ;
136146
137147 const readModeStyles = euiInlineEditReadModeStyles ( euiTheme ) ;
138148 const readModeCssStyles = [
139149 readModeStyles . euiInlineEditReadMode ,
140150 isReadOnly && readModeStyles . isReadOnly ,
151+ renderPlaceholder && readModeStyles . hasPlaceholder ,
141152 ] ;
142153
143154 const { controlHeight, controlCompressedHeight } = euiFormVariables ( euiTheme ) ;
@@ -169,7 +180,9 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
169180 ] ) ;
170181
171182 const [ isEditing , setIsEditing ] = useState ( false || startWithEditOpen ) ;
172- const [ editModeValue , setEditModeValue ] = useState ( defaultValue ) ;
183+ const [ editModeValue , setEditModeValue ] = useState (
184+ renderPlaceholder ? '' : defaultValue
185+ ) ;
173186 const [ readModeValue , setReadModeValue ] = useState ( defaultValue ) ;
174187
175188 const activateEditMode = ( ) => {
@@ -179,7 +192,8 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
179192 } ;
180193
181194 const cancelInlineEdit = ( ) => {
182- setEditModeValue ( readModeValue ) ;
195+ // When a placeholder is set, but the save is cancelled, do not change `editModeValue`
196+ renderPlaceholder ? setEditModeValue ( '' ) : setEditModeValue ( readModeValue ) ;
183197 setIsEditing ( false ) ;
184198 requestAnimationFrame ( ( ) => readModeFocusRef . current ?. focus ( ) ) ;
185199 } ;
@@ -193,6 +207,9 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
193207 if ( awaitedReturn === false ) return ;
194208 }
195209
210+ // If a placeholder is present the first time that a text value is saved,
211+ // remove placeholder related settings
212+ renderPlaceholder && setRenderPlaceholder ( false ) ;
196213 setReadModeValue ( editModeValue ) ;
197214 setIsEditing ( false ) ;
198215 requestAnimationFrame ( ( ) => readModeFocusRef . current ?. focus ( ) ) ;
@@ -248,6 +265,7 @@ export const EuiInlineEditForm: FunctionComponent<EuiInlineEditFormProps> = ({
248265 editModeDescribedById ,
249266 editModeProps ?. inputProps ?. [ 'aria-describedby' ]
250267 ) }
268+ placeholder = { renderPlaceholder ? defaultValue : undefined }
251269 />
252270 </ EuiFormRow >
253271 < span id = { editModeDescribedById } hidden >
0 commit comments