Skip to content

Commit

Permalink
fix(component): nowrap inline-edit (#5844)
Browse files Browse the repository at this point in the history
  • Loading branch information
CatsJuice committed Feb 21, 2024
1 parent 201f680 commit ed0d67e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/frontend/component/src/ui/editable/inline-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
useCallback,
useEffect,
useImperativeHandle,
useMemo,
useRef,
useState,
} from 'react';
Expand Down Expand Up @@ -139,6 +140,11 @@ export const InlineEdit = ({
setEditingValue(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
const inputWrapperInheritsStyles = {
margin: 'inherit',
Expand Down Expand Up @@ -172,9 +178,9 @@ export const InlineEdit = ({
onDoubleClick={onDoubleClick}
className={clsx(styles.inlineEdit)}
>
{editingValue}
{displayValue}

{!editingValue && (
{!displayValue && (
<Placeholder
className={placeholderClassName}
label={placeholder}
Expand Down

0 comments on commit ed0d67e

Please sign in to comment.