-
Notifications
You must be signed in to change notification settings - Fork 106
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
Anchor element specific properties for Button #108
Comments
Hi @MrSquaare, We previously attempted button/anchor polymorphism (modelled after reactstrap specifically) but I removed it in #72. The reason being that it caused type safety issues. We may attempt it again in the future, and if you would like to open a PR it would be very welcome! Personally, I would rather keep the code as clean and type safe as possible, even if it comes with a small loss of flexibility. My thinking when removing it was that a user who uses a |
Hello @benjitrosch, I didn't know there was an attempt before. I tried in the evening to find some solutions, but I always have compromises. I found a blog post (that you may have already consulted) that I adapted for the Button component and that seemed to be the best: https://www.benmvp.com/blog/forwarding-refs-polymorphic-react-component-typescript/. The only problem is that TypeScript seems to do a lot of operations to deduce the valid types. What do you think about it? |
My 2 cents. There are 3 usescases I could think of.
|
Currently, if the
href
property is set to aButton
component, the anchor element is used.However, it is not possible to use anchor specific properties like
rel
ortarget
.A solution to multi-element components is to propose a property (react-bootstrap named it
as
, reactstrap named ittag
) allowing to specify the type of element (in the case of theButton
component, it would be eitherbutton
ora
). It is then possible to determine from the latter the properties specific to an element.The text was updated successfully, but these errors were encountered: