diff --git a/semcore/inline-input/src/InlineInput.tsx b/semcore/inline-input/src/InlineInput.tsx index e804bb1e9d..951f231f56 100644 --- a/semcore/inline-input/src/InlineInput.tsx +++ b/semcore/inline-input/src/InlineInput.tsx @@ -64,6 +64,7 @@ type ControlAsProps = { }; type ConfirmControlAsProps = ControlAsProps & { onConfirm?: OnConfirm; + onCancel?: OnCancel; inputRef?: React.RefObject; }; type CancelControlAsProps = ControlAsProps & { @@ -163,6 +164,7 @@ class InlineInputBase extends Component< inputRef: this.inputRef, loading, onConfirm: this.handleConfirm, + onCancel: this.handleCancel, getI18nText, }; } @@ -324,7 +326,7 @@ function Addon(props: AddonAsProps) { function ConfirmControl(props: ConfirmControlAsProps) { const SAddon = Root; - const { Children, children: hasChildren, inputRef } = props; + const { Children, children: hasChildren, inputRef, onCancel } = props; const title = props.title ?? props.getI18nText('confirm'); const handleConfirm = React.useCallback( @@ -341,6 +343,11 @@ function ConfirmControl(props: ConfirmControlAsProps) { event.stopPropagation(); handleConfirm(event); } + if (event.key === 'Escape') { + event.preventDefault(); + event.stopPropagation(); + onCancel?.(inputRef?.current?.value ?? '', event); + } }, [handleConfirm], ); @@ -388,7 +395,7 @@ function CancelControl(props: CancelControlAsProps) { const handleKeydown = React.useCallback( (event: React.KeyboardEvent) => { - if (event.key === 'Enter' || event.key === ' ') { + if (event.key === 'Enter' || event.key === ' ' || event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); handleCancel(event);