portabletext / portabletext/react-portabletext
[Feature Request] Provide a sort mechanism to define render order of marks
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 377
- Forks
- 31
- Avg merge
- 23h 42m
- Merged PRs (30d)
- 9
Description
Hi,
Currently marks render alphabetically and I'm facing a use case where I need to have a mark render before another.
See this codesandbox.
Issue
I need elements with .border to be rendered as child of .color. Currently border mark renders first because of alphabetically sorting.
.color {
color: red;
}
.border {
border: 1px solid currentColor;
}
Proposal
Providing a marksOrder prop to force some marks to render in a specific order.
All other marks will render after.
Using '*' will define the position of all others marks ['*', 'myMark'].
const components = {
marks: {
color: ({children}) => <span className="color">{children}</span>,
border: ({children}) => <span className="border">{children}</span>,
},
marksOrder: ['color', 'border'], // equivalent to `['color', 'border', '*']`
// marksOrder: ['*', 'color', 'border'], // render all before those specifics marks
}
Thanks
Contributor guide
No contributing guide indexed for this repository
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
Start by tracing how marks are sorted and rendered in the React components, using the App.js example in the linked CodeSandbox to reproduce the ordering problem. Implement the proposed marksOrder behavior, including the '*' position, and verify that specified marks render in order while unspecified marks follow the defined rule.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100