Add an HTML attribute tool
Paths are relative to apps/frontend/src/app/(dashboard)/editor/[projectId]/[pageId]/Components/PropsController/.
-
Open
attrToolDefinitions.tsxand pick the group inATTR_TOOL_GROUPS. -
Add a
fieldToolwith anappliesTopredicate:fieldTool( "html-search-input", "Search input", [ TEXT("placeholder", "Search…"), { kind: "idref", attr: "list", filter: (n) => n.tag === "datalist" }, BOOL("required"), ], inputTypes("search") ),Use
tags(...)for element tags,inputTypes(...)forinputtypes, or any(ctx) => boolean. Omit it for global attributes. -
Prefix the id with
html-so its open state doesn’t collide with a Style tool id. -
For attributes where an empty value has a meaning, use
emptyAs(select/segmented) oremptyToggle(text). Otherwise an empty input removes the attribute. -
Run
npx tsc --noEmitandnpx eslinton the folder, then check the tool with one element, several elements of the same tag, and a mixed selection.
Common variations
- Custom tool. Create
tools/MyTool.tsx, useuseAttrTool()fornodes/attributesanduseAttrWriter()for writes (nullremoves). Register{ id, title, attributes, appliesTo, render: () => <MyTool /> }; addcountif the badge shouldn’t be derived fromattributes. - Page head setting. Add a
HeadFieldSpecto aheadFieldTool(...)in the Page settings group, e.g.meta("Author", "author"). - Elements other than the selection. Pass
nodes={[node]}toAttrField/AttrRow, or{ nodes }tosetAttributes.
Troubleshooting
- The tool never shows.
ctx.tagisnullfor mixed-tag selections; check the predicate with a single element first. - A boolean attribute can’t be turned off. Use
kind: "boolean"; writing""keeps the attribute present.
Related
- Reference: Props tools framework