fix(component): nowrap inline-edit (#5844)
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
@@ -139,6 +140,11 @@ export const InlineEdit = ({
|
|||||||
setEditingValue(value);
|
setEditingValue(value);
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
|
// to make sure text is not wrapped, and multi-space is shown normally
|
||||||
|
const displayValue = useMemo(() => {
|
||||||
|
return editingValue ? editingValue.replace(/\n/g, '') : '';
|
||||||
|
}, [editingValue]);
|
||||||
|
|
||||||
// to make sure input's style is the same as displayed text
|
// to make sure input's style is the same as displayed text
|
||||||
const inputWrapperInheritsStyles = {
|
const inputWrapperInheritsStyles = {
|
||||||
margin: 'inherit',
|
margin: 'inherit',
|
||||||
@@ -172,9 +178,9 @@ export const InlineEdit = ({
|
|||||||
onDoubleClick={onDoubleClick}
|
onDoubleClick={onDoubleClick}
|
||||||
className={clsx(styles.inlineEdit)}
|
className={clsx(styles.inlineEdit)}
|
||||||
>
|
>
|
||||||
{editingValue}
|
{displayValue}
|
||||||
|
|
||||||
{!editingValue && (
|
{!displayValue && (
|
||||||
<Placeholder
|
<Placeholder
|
||||||
className={placeholderClassName}
|
className={placeholderClassName}
|
||||||
label={placeholder}
|
label={placeholder}
|
||||||
|
|||||||
Reference in New Issue
Block a user