Skip to content

Commit 4e775d9

Browse files
authored
fix: set true by default for new boolean properties/attributes (#5362)
Before we set false by default for boolean properties and attributes which is less intuitive and always requires additional click to switch boolean on. Now when user add for example aria-atomic attribute it gets true by default. When user see initial property, for example disabled in input element, it gets false. <img width="241" height="585" alt="Screenshot 2025-08-07 at 19 40 22" src="https://github.com/user-attachments/assets/9574e885-febb-42e5-8dd4-a7984a31b0b5" />
1 parent d3da479 commit 4e775d9

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

apps/builder/app/builder/features/settings-panel/props-section/use-props-logic.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export type PropAndMeta = {
4343
// - when they open props panel again, the prop is not there
4444
//
4545
// We want to avoid this if possible, but for some types like "asset" we can't
46-
export const getStartingValue = (meta: PropMeta): PropValue | undefined => {
46+
const getStartingValue = (
47+
meta: PropMeta,
48+
defaultBooleanValue: boolean
49+
): PropValue | undefined => {
4750
if (meta.type === "string" && meta.control !== "file") {
4851
return {
4952
type: "string",
@@ -61,7 +64,7 @@ export const getStartingValue = (meta: PropMeta): PropValue | undefined => {
6164
if (meta.type === "boolean") {
6265
return {
6366
type: "boolean",
64-
value: meta.defaultValue ?? false,
67+
value: meta.defaultValue ?? defaultBooleanValue,
6568
};
6669
}
6770

@@ -80,15 +83,6 @@ export const getStartingValue = (meta: PropMeta): PropValue | undefined => {
8083
}
8184
};
8285

83-
const getStartingProp = (
84-
instanceId: Instance["id"],
85-
meta: PropMeta,
86-
name: string
87-
): Prop | undefined => {
88-
const value = getStartingValue(meta);
89-
return value && { id: nanoid(), instanceId, name, ...value };
90-
};
91-
9286
const getDefaultMetaForType = (type: Prop["type"]): PropMeta => {
9387
switch (type) {
9488
case "action":
@@ -258,15 +252,19 @@ export const usePropsLogic = ({
258252

259253
// For initial props, if prop is not saved, we want to show default value if available.
260254
//
261-
// Important to not use getStartingProp if default is not available
255+
// Important to not use infer stating value if default is not available
262256
// beacuse user may have this experience:
263257
// - they open props panel of an Image
264258
// - they see 0 in the control for "width"
265259
// - where 0 is a fallback when no default is available
266260
// - they think that width is set to 0, but it's actually not set at all
267261
//
268262
if (prop === undefined && propMeta.defaultValue !== undefined) {
269-
prop = getStartingProp(instance.id, propMeta, name);
263+
// initial properties are not defined but suggested to default so default boolean is false
264+
const value = getStartingValue(propMeta, false);
265+
if (value) {
266+
prop = { id: nanoid(), instanceId: instance.id, name, ...value };
267+
}
270268
}
271269

272270
initialProps.push({
@@ -303,9 +301,14 @@ export const usePropsLogic = ({
303301
// In case of custom property/attribute we get a string.
304302
const propMeta =
305303
propsMetas.get(propName) ?? getDefaultMetaForType("string");
306-
const prop = getStartingProp(instance.id, propMeta, propName);
307-
if (prop) {
308-
updateProp(prop);
304+
const value = getStartingValue(propMeta, true);
305+
if (value) {
306+
updateProp({
307+
id: nanoid(),
308+
instanceId: instance.id,
309+
name: propName,
310+
...value,
311+
});
309312
}
310313
};
311314

0 commit comments

Comments
 (0)