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

[EuiInputPopover] Refactor & clean ups #7241

Merged
merged 6 commits into from
Oct 2, 2023

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Oct 1, 2023

Summary

I'm working on pulling out some logic that EuiComboBox needs directly into EuiInputPopover for #7192, and was struggling to understand and work around some of the existing logic. Since I saw several things that bothered me/that could stand to be cleaned up, I decided to do my favorite thing - refactor and write missing tests 😅

I've opted to make this refactor separate/standalone from my EuiComboBox work in order to make code review less of a headache. As always, I strongly recommend following along by commit and hiding whitespace changes (the scary LOC diffs on this PR are literally just from indentation changes on snapshots).

What this PR does:

  • Removes an extra unnecessary <div> in the popover
  • Updates inline width style to use logical inline-size property instead of width
  • Memoizes and greatly cleans up onKeydown callback
  • Generally tries to make the code more understandable and adds more comments as to why specific things are done a specific way
  • Adds more EuiInputPopover tests to automatically catch if code changes/breaks something that was meant to do a specific thing a specific way

QA

Functionally, nothing should have changed in this PR except for 2 removed <div> wrappers and a logical property.

General checklist

  • Browser QA
    • Checked in mobile
    • Checked in Chrome, Safari, Edge, and Firefox
    • Checked for accessibility including keyboard-only and screenreader modes
      - [ ] Checked in both light and dark modes
  • Docs site QA - N/A
  • Code quality checklist
  • Release checklist - ❓ skipping changelog as nothing affecting end-users or consumers should have occurred, but I'd be curious to hear if y'all feel there should be one
  • Designer checklist - N/A

- allows us to remove an extra unnecessary div wrapper, and it general lends itself to cleaner and more React-like code

+ add more detailed/clearer tests to reflect the comments added to the useEffects
- [microperf] don't bother finding/iterating through tabbable items when `disableFocusTrap` is true

- [microperf] Clean up unnecessary extra Array map by using `.hasAttribute()` instead

- make if conditions more readable/understandable by using early returns, var names, and writing tests

- pull out `closePopover` from props to add it to dependency array

- remove unnecessary type
- Remove unnecessary div by passing onKeyDown to the parent EuiPanel popover

- now that the current target of the keydown event can be guaranteed to be the panel, we can remove the `panelEl` dependency from the array
- Move classes/styling up to top of file
- add jsdoc block
- add clearer comments on why state is being used over refs for the input/panel refs
@kibanamachine
Copy link

Preview staging links for this PR:

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

@cee-chen cee-chen marked this pull request as ready for review October 2, 2023 15:44
@cee-chen cee-chen requested a review from a team as a code owner October 2, 2023 15:44
@cee-chen
Copy link
Member Author

cee-chen commented Oct 2, 2023

@breehall Any chance I can shoot this PR your way today/tomorrow for review? 🙏 It's somewhat high priority as it's blocking another EuiComboBox PR. If you don't have bandwidth, no worries, please let me know!

@cee-chen cee-chen requested a review from breehall October 2, 2023 17:23
@breehall
Copy link
Contributor

breehall commented Oct 2, 2023

Absolutely! Taking a look now

Copy link
Contributor

@breehall breehall left a comment

Choose a reason for hiding this comment

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

This is good to go! This was a good refactor with great code quality improvements around comments, readability, and code structure. Great work simplifying the portion of code used to set width on the popover and removing an unnecessary .map(). I tested the production and staging versions of the PR and don't see any changes visually or in functionality.

Comment on lines +79 to +83
const inputWidth = useResizeObserver(inputEl, 'width').width;

const panelWidth = useMemo(() => {
return inputWidth < panelMinWidth ? panelMinWidth : inputWidth;
}, [panelMinWidth, inputWidth]);
Copy link
Contributor

Choose a reason for hiding this comment

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

[Attaching to the closest block of code] This is a lot easier to understand (especially with the new comments)

Copy link
Member Author

Choose a reason for hiding this comment

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

Music to my ears. Thank you so much Bree!

Also, for some context as to what I was cursing about & struggling with that I mentioned earlier today - it took me way too long to figure out what the tabbable logic was trying to accomplish and how to QA it (it really seems, functionally, to only affect the EuiAutoRefresh component). Which is why writing tests and leaving good code comments is so important :)

@cee-chen cee-chen merged commit 10a50bb into elastic:main Oct 2, 2023
2 checks passed
@cee-chen cee-chen deleted the input-popover-setup branch October 2, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants