1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

prevent EditableList input from blurring

Signed-off-by: ndrscodes <ndrscodes@gmail.com>
This commit is contained in:
Andreas Schmidt 2022-01-14 16:41:43 +01:00 committed by ndrscodes
parent 1eef2bca2b
commit 0d134ed5cb
2 changed files with 8 additions and 2 deletions

View File

@ -56,6 +56,7 @@ export class EditableList<T> extends React.Component<Props<T>> {
if (val) { if (val) {
evt.preventDefault(); evt.preventDefault();
this.props.add(val); this.props.add(val);
evt.stopPropagation();
} }
} }
@ -70,6 +71,7 @@ export class EditableList<T> extends React.Component<Props<T>> {
onSubmit={this.onSubmit} onSubmit={this.onSubmit}
validators={validators} validators={validators}
placeholder={placeholder} placeholder={placeholder}
blurOnEnter={false}
iconRight={({ isDirty }) => isDirty ? <Icon material="keyboard_return" size={16} /> : null} iconRight={({ isDirty }) => isDirty ? <Icon material="keyboard_return" size={16} /> : null}
/> />
</div> </div>

View File

@ -68,6 +68,7 @@ export type InputProps = Omit<InputElementProps, "onChange" | "onSubmit"> & {
iconRight?: IconData; iconRight?: IconData;
contentRight?: string | React.ReactNode; // Any component of string goes after iconRight contentRight?: string | React.ReactNode; // Any component of string goes after iconRight
validators?: InputValidator | InputValidator[]; validators?: InputValidator | InputValidator[];
blurOnEnter?: boolean;
onChange?(value: string, evt: React.ChangeEvent<InputElement>): void; onChange?(value: string, evt: React.ChangeEvent<InputElement>): void;
onSubmit?(value: string, evt: React.KeyboardEvent<InputElement>): void; onSubmit?(value: string, evt: React.KeyboardEvent<InputElement>): void;
}; };
@ -86,6 +87,7 @@ const defaultProps: Partial<InputProps> = {
maxRows: 10000, maxRows: 10000,
showValidationLine: true, showValidationLine: true,
validators: [], validators: [],
blurOnEnter: true,
}; };
export class Input extends React.Component<InputProps, State> { export class Input extends React.Component<InputProps, State> {
@ -284,8 +286,10 @@ export class Input extends React.Component<InputProps, State> {
this.setDirty(); this.setDirty();
} }
//pressing enter indicates that the edit is complete, we can unfocus now if(this.props.blurOnEnter){
this.blur(); //pressing enter indicates that the edit is complete, we can unfocus now
this.blur();
}
} }
} }