Skip to content

chore: Add onEnter and onEscape to Input Component#1850

Open
camielvs wants to merge 1 commit into02-23-feat_submit_pipeline_tags_on_runsfrom
02-23-chore_add_onenter_and_onescape_to_input_component
Open

chore: Add onEnter and onEscape to Input Component#1850
camielvs wants to merge 1 commit into02-23-feat_submit_pipeline_tags_on_runsfrom
02-23-chore_add_onenter_and_onescape_to_input_component

Conversation

@camielvs
Copy link
Collaborator

@camielvs camielvs commented Feb 23, 2026

Description

Add native onEnter and onEscape handlers to Input component to streamline use of these common actions.

Related Issue and Pull requests

Type of Change

  • Cleanup/Refactor

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Screenshots (if applicable)

Test Instructions

  • All affected input fields should behave as expected

Additional Comments

@camielvs camielvs mentioned this pull request Feb 23, 2026
3 tasks
Copy link
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@camielvs camielvs force-pushed the 02-23-chore_add_onenter_and_onescape_to_input_component branch from e07ea07 to 39e086e Compare February 23, 2026 22:00
@camielvs camielvs marked this pull request as ready for review February 23, 2026 22:01
@camielvs camielvs requested a review from a team as a code owner February 23, 2026 22:01
Comment on lines +32 to +33
onEnter?: () => void;
onEscape?: () => void;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like the idea - simplifies a lot. I noticed that in most cases onEnter means "onSave" and "onEscape" means "onCancel". So maybe we should name them same way?

E.g. in InlineTextEditor same named as "onSave" and "onCancel" - we may introduce naming inconsistencies or establish a good convention.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe... I can see the merit in this. onSave and onClose and more descriptive and nicer to work with.

One thing I like about onEnter and onEscape is that its syntactically ambiguous and thus does not assume anything about what the keys are doing. If we ever need to use the enter key or escape key for actions other than the typical save/close then it's clear how to go about achieving this and we wouldn't need to add any additional logic.

My gut feeling for now is to keep as-is but I am not attached. If you feel strongly about switching to onSave and onClose then I am happy to change.

@camielvs camielvs requested a review from maxy-shpfy March 3, 2026 00:06
@camielvs camielvs force-pushed the 02-23-chore_add_onenter_and_onescape_to_input_component branch from 39e086e to 422e5be Compare March 3, 2026 00:06
@camielvs camielvs force-pushed the 02-23-feat_submit_pipeline_tags_on_runs branch from e5b794e to 075d6c9 Compare March 3, 2026 00:06
@github-actions
Copy link

github-actions bot commented Mar 3, 2026

🎩 To tophat this PR:

You can add the following URL parameter to your browser to tophat this PR:

`?tophat_location=02-23-chore_add_onenter_and_onescape_to_input_component/422e5be`

onEscape();
}
}}
{...props}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: onKeyDown might be overridden if to provide props. We may make it safe. But up to you

function Input({
  className,
  type,
  readOnly,
  variant = readOnly ? "readOnly" : "default",
  onEnter,
  onEscape,
  onKeyDown,
  ...props
}: ...) {
  const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
    if (e.key === "Enter" && onEnter) {
      e.preventDefault();
      e.stopPropagation();
      onEnter();
    } else if (e.key === "Escape" && onEscape) {
      e.preventDefault();
      e.stopPropagation();
      onEscape();
    }
    onKeyDown?.(e);
  };

  return (
    <input
      ...
      onKeyDown={handleKeyDown}
      {...props}  // no longer contains onKeyDown
    />
  );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants