-
Notifications
You must be signed in to change notification settings - Fork 839
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
Conversation
Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/ |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/ |
There was a problem hiding this 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.
Preview documentation changes for this PR: https://eui.elastic.co/pr_4940/ |
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 usesReact.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:href
can be used on anything)href
can't be used even on ana
)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 accessibility including keyboard-only and screenreader modes