Limit block rows or alternative to block for single decorator?
Based on the information I found, there is no built-in rows option for Portable Text (block) fields like there is for simple text fields. This is a known limitation that has been requested by the community.
However, there are a couple of approaches you can take:
CSS Workaround
You can limit the height of the Portable Text editor using CSS overrides. According to a community discussion, you can add this to your Studio styling overrides:
:global([class^="PortableTextInput_editorBoxContent"]) {
height: 8rem;
}Note: This approach will affect all block content fields in your Studio. To target a specific field, you'd need to find a way to add a custom class or use more specific CSS selectors based on the field's position in the DOM.
Consider Using a Simple Text Field
Since you mentioned:
- You only need one decorator (for pink text)
- It will never be a long text
You might want to reconsider whether you actually need a full Portable Text block. If you only need basic inline styling and no other block features (like headings, lists, custom blocks, etc.), you could use:
- A
textfield withrowsoption - This gives you the height control you want - A
stringfield - For single-line text
The downside is you'd lose the ability to apply that pink decorator inline. However, you could potentially:
- Use a separate boolean field to indicate if the text should be styled pink
- Create a custom input component that allows for simple inline styling while maintaining height control
Better Alternative: Custom Input Component
Since you only need one decorator, you might consider creating a custom input component that:
- Provides a simple text input with the
rowsattribute - Adds a button or keyboard shortcut to wrap selected text in a custom mark
- Stores the data in a simpler format than full Portable Text
This would give you better control over the UI while keeping the data structure simpler for your specific use case.
Feature Request
The ability to control Portable Text editor height (or have a "single-line" block variant) has been requested multiple times in the community. Consider upvoting or creating a feature request on Sanity's feedback channels if this is important for your use case.
Bottom line: The CSS workaround is currently your best option if you need to stick with Portable Text, but given your simple requirements (one decorator, short text), you might want to explore using a regular text field with rows or creating a custom input component that better fits your specific needs.
Show original thread7 replies
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.