Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EuiInlineEditForm] Support onCancel callback for non-controlled usage #8307

Merged

Conversation

mgadewoll
Copy link
Contributor

@mgadewoll mgadewoll commented Feb 4, 2025

Summary

This PR updates the type definition for EuiInlineEditForms onCancel prop to support using it for non-controlled usage next to the already available controlled usage.

When the component is in edit mode, we have two actions: "Save" and "Cancel" and currently only the "Save" action provides a callback for non-controlled usage.
Instead we should also allow onCancel to be always allowed considering that the action is always available too.
The main purpose of the onCancel callback is to reset the value in controlled usage, but there might be a need to use onCancel for non-controlled usages as well to handle other side effects.

Note

No functional changes have been made in this PR. The callback was already always technically available, just that the type definition prohibited its usage.

QA

  • checkout this PR and try the following combinations on e.g. EuiInlineEditTitle
    • using defaultValue & onCancel does not trigger a type error
    • using value & onChange and onCancel does not trigger a type error

General checklist

  • Browser QA
    • Checked in both light and dark modes
    • Checked in mobile
    • Checked in Chrome, Safari, Edge, and Firefox
    • Checked for accessibility including keyboard-only and screenreader modes
  • Docs site QA
  • Code quality checklist
  • Release checklist
    • A changelog entry exists and is marked appropriately.
    • If applicable, added the breaking change issue label (and filled out the breaking change checklist)
  • Designer checklist
    • If applicable, file an issue to update EUI's Figma library with any corresponding UI changes. (This is an internal repo, if you are external to Elastic, ask a maintainer to submit this request)

- allow usage also when not used as controlled component since the cancel action is always present
@mgadewoll mgadewoll force-pushed the inline-edit/update-cancel-callback-type branch from e460ff8 to 8fa75be Compare February 4, 2025 08:36
@mgadewoll mgadewoll marked this pull request as ready for review February 4, 2025 09:46
@mgadewoll mgadewoll requested a review from a team as a code owner February 4, 2025 09:46
@weronikaolejniczak weronikaolejniczak self-requested a review February 4, 2025 12:52
@tkajtoch
Copy link
Member

tkajtoch commented Feb 5, 2025

I'm not sure if this is expected or reproducible on your side, but I can't actually pass the QA steps provided. I'm getting onChange is not assignable to type undefined in both cases when I'm testing it in EuiInlineEditTitle

@mgadewoll
Copy link
Contributor Author

I'm not sure if this is expected or reproducible on your side, but I can't actually pass the QA steps provided. I'm getting onChange is not assignable to type undefined in both cases when I'm testing it in EuiInlineEditTitle

That's weird. No I don't see that error 🤔

These examples work fine for me:

// no onCancel
<EuiInlineEditTitle
   heading="h2"
   inputAriaLabel="Edit title inline"
   defaultValue="Hello World (but as a title)!"
 />
 
 // defaultValue & onCancel
<EuiInlineEditTitle
   heading="h2"
   inputAriaLabel="Edit title inline"
   defaultValue="Hello World (but as a title)!"
   onCancel={() => console.log('CANCEL')}
 />
 
 // value & onChange & onCancel
 <EuiInlineEditTitle
  heading="h2"
  inputAriaLabel="Edit title inline"
  value="Foobar"
  onChange={() => console.log('CHANGE')}
  onCancel={() => console.log('CANCEL')}
/>

Copy link
Contributor

@weronikaolejniczak weronikaolejniczak left a comment

Choose a reason for hiding this comment

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

Checked out the branch and tested the above-mentioned cases:

Screenshot 2025-02-07 at 13 12 58

Seems to be working as expected 👍🏻

@weronikaolejniczak
Copy link
Contributor

I noticed on another pipeline that this component's EuiInlineEditForm › toggling between read mode and edit mode › onSave validation › handles async promises test is flaky. Maybe something comes to mind how to improve it? If not, that's fine, we can move on 😄

Screenshot 2025-02-07 at 14 46 07

@mgadewoll
Copy link
Contributor Author

I noticed on another pipeline that this component's EuiInlineEditForm › toggling between read mode and edit mode › onSave validation › handles async promises test is flaky. Maybe something comes to mind how to improve it? If not, that's fine, we can move on 😄

Screenshot 2025-02-07 at 14 46 07

@weronikaolejniczak Yeah, this flaky test is known, it's not related to the changes themselves. The problem is that I haven't been able to reproduce it locally so I'm afraid this would create unrelated clutter in this PR by trying to figure out what's actually the issue. 🙈 I'd vote for checking on this separately.

@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @tkajtoch @weronikaolejniczak

@mgadewoll mgadewoll merged commit 0e31d35 into elastic:main Feb 11, 2025
5 checks passed
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.

5 participants