Skip to content

[EuiFlyout] Refactor polymorphic types - #4940

Merged
thompsongl merged 5 commits into
elastic:masterfrom
thompsongl:flyout-types
Jul 13, 2021
Merged

thompsongl merged 5 commits into
elastic:masterfrom
thompsongl:flyout-types

Conversation

@thompsongl

@thompsongl thompsongl commented Jul 7, 2021 •

Copy link
Copy Markdown
Contributor

Summary

We've tried a couple different approaches to solve the type problem in EuiFlyout, which is polymorphic (uses an as prop to set the underlying element), has an inferred type generic, and uses React.forwardRef. React.forwardRef interferes with the more correct types set via the prop type interface(s) and (without tradeoffs) will cause one of the following problems:

  • Overly generic props (e.g., href can be used on anything)
  • Overly specific props (e.g., href can't be used even on an a)
  • Overly large type definition that causes errors itself

We had "solved" this by curating a manual list of accepted HTML elements and creating a type from those. Working on adding Emotion, a new problem arose: the type idiosyncrasies prevent Emotion from appending the css prop, causing errors.

This PR changes the types again using targeted casting to get the flexibility we want while getting strict prop type checking for various elements. Also checked the changes against Kibana.

Also relevant to #4416

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile
- [ ] Checked in Chrome, Safari, Edge, and Firefox
- [ ] Props have proper autodocs and playground toggles
- [ ] Added documentation
- [ ] Checked Code Sandbox works for the any docs examples
- [ ] Added or updated jest tests

  • Checked for breaking changes and labeled appropriately

- [ ] Checked for accessibility including keyboard-only and screenreader modes

  • A changelog entry exists and is marked appropriately

@kibanamachine

Copy link
Copy Markdown
Contributor

@thompsongl
thompsongl marked this pull request as ready for review July 7, 2021 20:44
@thompsongl
thompsongl requested a review from chandlerprall July 8, 2021 15:13
@kibanamachine

Copy link
Copy Markdown
Contributor

@kibanamachine

Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice!! Tested locally by throwing different as+attribute combinations and it errors when expected, and works when expected.

Comment thread CHANGELOG.md Resolved
@kibanamachine

Copy link
Copy Markdown
Contributor

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.

3 participants