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

[EuiFlyout] Refactor polymorphic types #4940

Merged
merged 5 commits into from
Jul 13, 2021

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Jul 7, 2021

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

Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/

@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

Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/

Copy link
Contributor

@chandlerprall chandlerprall left a comment

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.

CHANGELOG.md Outdated Show resolved Hide resolved
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/

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