diff --git a/src-docs/src/views/inline_edit/inline_edit_example.js b/src-docs/src/views/inline_edit/inline_edit_example.js
index 5c57e1ca5ae..ebe59fa12f2 100644
--- a/src-docs/src/views/inline_edit/inline_edit_example.js
+++ b/src-docs/src/views/inline_edit/inline_edit_example.js
@@ -30,6 +30,14 @@ const inlineEditTitleSnippet = ` `;
+import InlineEditPlaceholder from './inline_edit_placeholder';
+const inlineEditPlaceholderSource = require('!!raw-loader!./inline_edit_placeholder');
+const inlineEditPlaceholderSnippet = ` `;
+
import InlineEditSave from './inline_edit_save';
const inlineEditSaveSource = require('!!raw-loader!././inline_edit_save');
const inlineEditModeSaveSnippet = ` ,
},
+ {
+ title: 'Setting placeholder instructions',
+ text: (
+ <>
+
`;
+exports[`EuiInlineEditForm read mode placeholder 1`] = `
+
+
+
+
+ This is a placeholder.
+
+
+
+
+
+ Click to edit this text inline.
+
+
+`;
+
exports[`EuiInlineEditForm read mode readModeProps 1`] = `
{
return {
@@ -21,5 +21,12 @@ export const euiInlineEditReadModeStyles = ({ euiTheme }: UseEuiTheme) => {
user-select: text;
}
`,
+
+ hasPlaceholder: css`
+ .euiText,
+ .euiTitle {
+ color: ${tint(euiTheme.colors.subduedText, 0.08)};
+ }
+ `,
};
};
diff --git a/src/components/inline_edit/inline_edit_form.test.tsx b/src/components/inline_edit/inline_edit_form.test.tsx
index 8d51e56c50d..c79d58bd728 100644
--- a/src/components/inline_edit/inline_edit_form.test.tsx
+++ b/src/components/inline_edit/inline_edit_form.test.tsx
@@ -75,6 +75,19 @@ describe('EuiInlineEditForm', () => {
expect(container.firstChild).toMatchSnapshot();
});
+
+ test('placeholder', () => {
+ const { container, getByText } = render(
+
+ );
+
+ expect(container.firstChild).toMatchSnapshot();
+ expect(getByText('This is a placeholder.')).toBeTruthy();
+ });
});
describe('edit mode', () => {
@@ -202,6 +215,25 @@ describe('EuiInlineEditForm', () => {
getByTestSubject('euiInlineEditModeInput').hasAttribute('aria-invalid')
).toBeTruthy();
});
+
+ test('placeholder', () => {
+ const { container, getByTestSubject } = render(
+
+ );
+
+ expect(container.firstChild).toMatchSnapshot();
+ expect(
+ getByTestSubject('euiInlineEditModeInput').getAttribute('placeholder')
+ ).toBeTruthy();
+ expect(
+ getByTestSubject('euiInlineEditModeInput').getAttribute('value')
+ ).toBeFalsy();
+ });
});
describe('toggling between read mode and edit mode', () => {
@@ -448,6 +480,26 @@ describe('EuiInlineEditForm', () => {
expect(getByTestSubject('euiInlineReadModeButton')).toBeTruthy();
expect(getByText('New message!')).toBeTruthy();
});
+
+ it('allows overriding `placeholder` with `inputModeProps.placeholder`', () => {
+ const { getByTestSubject } = render(
+
+ );
+
+ expect(
+ getByTestSubject('euiInlineEditModeInput').getAttribute('placeholder')
+ ).toEqual('The real placeholder!');
+ });
});
});
});
diff --git a/src/components/inline_edit/inline_edit_form.tsx b/src/components/inline_edit/inline_edit_form.tsx
index 3793f5e5213..90feb3c86a7 100644
--- a/src/components/inline_edit/inline_edit_form.tsx
+++ b/src/components/inline_edit/inline_edit_form.tsx
@@ -40,6 +40,7 @@ import { euiInlineEditReadModeStyles } from './inline_edit_form.styles';
export type EuiInlineEditCommonProps = HTMLAttributes &
CommonProps & {
defaultValue: string;
+ placeholder?: string;
/**
* Callback that fires when a user clicks the save button.
* Passes the current edited text value as an argument.
@@ -121,6 +122,7 @@ export const EuiInlineEditForm: FunctionComponent = ({
children,
sizes,
defaultValue,
+ placeholder,
inputAriaLabel,
startWithEditOpen,
readModeProps,
@@ -134,12 +136,6 @@ export const EuiInlineEditForm: FunctionComponent = ({
const euiTheme = useEuiTheme();
- const readModeStyles = euiInlineEditReadModeStyles(euiTheme);
- const readModeCssStyles = [
- readModeStyles.euiInlineEditReadMode,
- isReadOnly && readModeStyles.isReadOnly,
- ];
-
const { controlHeight, controlCompressedHeight } = euiFormVariables(euiTheme);
const loadingSkeletonSize = sizes.compressed
? controlCompressedHeight
@@ -172,6 +168,13 @@ export const EuiInlineEditForm: FunctionComponent = ({
const [editModeValue, setEditModeValue] = useState(defaultValue);
const [readModeValue, setReadModeValue] = useState(defaultValue);
+ const readModeStyles = euiInlineEditReadModeStyles(euiTheme);
+ const readModeCssStyles = [
+ readModeStyles.euiInlineEditReadMode,
+ isReadOnly && readModeStyles.isReadOnly,
+ placeholder && !readModeValue && readModeStyles.hasPlaceholder,
+ ];
+
const activateEditMode = () => {
setIsEditing(true);
// Waits a tick for state to settle and the focus target to render
@@ -234,6 +237,7 @@ export const EuiInlineEditForm: FunctionComponent = ({
isInvalid={isInvalid}
isLoading={isLoading}
data-test-subj="euiInlineEditModeInput"
+ placeholder={placeholder}
{...editModeProps?.inputProps}
inputRef={setEditModeRefs}
onChange={(e) => {
@@ -337,7 +341,7 @@ export const EuiInlineEditForm: FunctionComponent = ({
readModeProps?.onClick?.(e);
}}
>
- {children(readModeValue)}
+ {children(readModeValue || placeholder)}
{!isReadOnly && (
diff --git a/src/components/inline_edit/inline_edit_text.tsx b/src/components/inline_edit/inline_edit_text.tsx
index 8015b7ac141..217916954a3 100644
--- a/src/components/inline_edit/inline_edit_text.tsx
+++ b/src/components/inline_edit/inline_edit_text.tsx
@@ -32,6 +32,7 @@ export const EuiInlineEditText: FunctionComponent = ({
className,
size = 'm',
defaultValue,
+ placeholder,
inputAriaLabel,
startWithEditOpen,
readModeProps: _readModeProps,
@@ -62,6 +63,7 @@ export const EuiInlineEditText: FunctionComponent = ({
const formProps = {
sizes,
defaultValue,
+ placeholder,
inputAriaLabel,
startWithEditOpen,
readModeProps,
diff --git a/src/components/inline_edit/inline_edit_title.tsx b/src/components/inline_edit/inline_edit_title.tsx
index 37c1ebae218..aa87d82bf26 100644
--- a/src/components/inline_edit/inline_edit_title.tsx
+++ b/src/components/inline_edit/inline_edit_title.tsx
@@ -39,6 +39,7 @@ export const EuiInlineEditTitle: FunctionComponent = ({
size = 'm',
heading,
defaultValue,
+ placeholder,
inputAriaLabel,
startWithEditOpen,
readModeProps: _readModeProps,
@@ -78,6 +79,7 @@ export const EuiInlineEditTitle: FunctionComponent = ({
const formProps = {
sizes,
defaultValue,
+ placeholder,
inputAriaLabel,
startWithEditOpen,
readModeProps,
diff --git a/upcoming_changelogs/6883.md b/upcoming_changelogs/6883.md
new file mode 100644
index 00000000000..a1dc6279886
--- /dev/null
+++ b/upcoming_changelogs/6883.md
@@ -0,0 +1 @@
+- Added `placeholder` prop to `EuiInlineEdit`