patternfly / patternfly/patternfly-react
Resolve inconsistencies when forwarding components
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 862
- Forks
- 392
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 9
Description
Describe the issue. What is the expected and unexpected behavior?
Sometimes as a user you want to be able to pass in your custom component to render instead of the default element. However the API around this varies wildly per component. For example, these are some components we use in our application that need React Router's Link component:
Button
{/* @ts-ignore */}
<Button component={Link} to={toNewClientScope({ realm })}>
{t("createClientScope")}
</Button>
DropdownItem
<DropdownItem
component={<Link to={toDashboard({ realm })}>{t("realmInfo")}</Link>}
/>
BreadcrumbItem
<BreadcrumbItem
render={(props) => (
<Link {...props} to={toRealmSettings({ realm, tab: "keys" })}>
{t("keys")}
</Link>
)}
/>
As you can see there are already three different ways of forwarding a component to render, and some of them are not able to be written in a type-safe manner.
The expected behavior here would be that this is a single and consistent API that is completely type-safe. For example, Styled Components has a as prop which is made type-safe by the definitions and allows the props to be forwarded and type-checked as well:
import styled from 'styled-components'
const Button = styled.button`
background-color: hotpink;
`
<Button component={Link} to={toNewClientScope({ realm })}>
{t("createClientScope")}
</Button>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Compare the forwarding APIs and TypeScript behavior of Button, DropdownItem, and BreadcrumbItem, using the styled-components type definitions linked in the issue as a reference. The work is complete when these components expose one consistent, type-safe way to forward a custom component and its props.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100