Skip to content

Commit f837456

Browse files
authored
feat: Reset any css value when user deletes the input and hits enter (#4491)
## Description closes #4481 ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 93fc476 commit f837456

File tree

11 files changed

+68
-1
lines changed

11 files changed

+68
-1
lines changed

apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export const ColorControl = ({ property }: { property: StyleProperty }) => {
2727
onChange={(styleValue) => setValue(styleValue, { isEphemeral: true })}
2828
onChangeComplete={setValue}
2929
onAbort={() => deleteProperty(property, { isEphemeral: true })}
30+
onReset={() => {
31+
deleteProperty(property);
32+
}}
3033
/>
3134
);
3235
};

apps/builder/app/builder/features/style-panel/controls/text/text-control.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export const TextControl = ({ property }: { property: StyleProperty }) => {
5555
onAbort={() => {
5656
deleteProperty(property, { isEphemeral: true });
5757
}}
58+
onReset={() => {
59+
setIntermediateValue(undefined);
60+
deleteProperty(property);
61+
}}
5862
/>
5963
);
6064
};

apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export const BorderColor = () => {
8484
}
8585
batch.publish({ isEphemeral: true });
8686
}}
87+
onReset={() => {
88+
const batch = createBatchUpdate();
89+
for (const property of properties) {
90+
batch.deleteProperty(property);
91+
}
92+
batch.publish();
93+
}}
8794
/>
8895
</div>
8996
</PropertyValueTooltip>

apps/builder/app/builder/features/style-panel/sections/layout/layout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ const GapInput = ({
183183
onAbort={() => {
184184
onPreviewChange();
185185
}}
186+
onReset={() => {
187+
onIntermediateChange(undefined);
188+
onReset();
189+
}}
186190
/>
187191
</Box>
188192
);

apps/builder/app/builder/features/style-panel/sections/shared/input-popover.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ const Input = ({
7777
batch.publish({ isEphemeral: true });
7878
}}
7979
onChangeComplete={({ value }) => {
80-
const batch = createBatchUpdate();
8180
setIntermediateValue(undefined);
81+
const batch = createBatchUpdate();
8282
for (const property of activeProperties) {
8383
batch.setProperty(property)(value);
8484
}
@@ -90,6 +90,15 @@ const Input = ({
9090
batch.deleteProperty(property);
9191
batch.publish({ isEphemeral: true });
9292
}}
93+
onReset={() => {
94+
setIntermediateValue(undefined);
95+
const batch = createBatchUpdate();
96+
for (const property of activeProperties) {
97+
batch.deleteProperty(property);
98+
}
99+
batch.publish();
100+
onClosePopover();
101+
}}
93102
/>
94103
);
95104
};

apps/builder/app/builder/features/style-panel/sections/transforms/transform-scale.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ export const ScalePanelContent = () => {
127127
}
128128
}}
129129
onAbort={() => deleteProperty(property, { isEphemeral: true })}
130+
onReset={() => {
131+
deleteProperty(property);
132+
}}
130133
/>
131134
</Grid>
132135
<Grid
@@ -168,6 +171,9 @@ export const ScalePanelContent = () => {
168171
}
169172
}}
170173
onAbort={() => deleteProperty(property, { isEphemeral: true })}
174+
onReset={() => {
175+
deleteProperty(property);
176+
}}
171177
/>
172178
</Grid>
173179
<Grid
@@ -205,6 +211,9 @@ export const ScalePanelContent = () => {
205211
}
206212
}}
207213
onAbort={() => deleteProperty(property, { isEphemeral: true })}
214+
onReset={() => {
215+
deleteProperty(property);
216+
}}
208217
/>
209218
</Grid>
210219
</Flex>

apps/builder/app/builder/features/style-panel/shared/color-picker.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const ColorPickerPopoverContent = ({
169169
type ColorPickerProps = {
170170
onChange: (value: StyleValue) => void;
171171
onChangeComplete: (value: StyleValue) => void;
172+
onReset: () => void;
172173
onAbort: () => void;
173174
value: StyleValue;
174175
currentColor: StyleValue;
@@ -243,6 +244,7 @@ export const ColorPicker = ({
243244
onChange,
244245
onChangeComplete,
245246
onAbort,
247+
onReset,
246248
}: ColorPickerProps) => {
247249
const [intermediateValue, setIntermediateValue] = useState<
248250
StyleValue | IntermediateStyleValue
@@ -326,6 +328,10 @@ export const ColorPicker = ({
326328
onChange(invalidValue);
327329
}}
328330
onAbort={onAbort}
331+
onReset={() => {
332+
setIntermediateValue(undefined);
333+
onReset();
334+
}}
329335
/>
330336
);
331337
};

apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input-container.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type CssValueInputContainerProps = {
1111
| "onChange"
1212
| "onHighlight"
1313
| "onChangeComplete"
14+
| "onReset"
1415
| "onAbort"
1516
| "intermediateValue"
1617
>;
@@ -56,6 +57,9 @@ export const CssValueInputContainer = ({
5657
onAbort={() => {
5758
deleteProperty(property, { isEphemeral: true });
5859
}}
60+
onReset={() => {
61+
deleteProperty(property);
62+
}}
5963
/>
6064
);
6165
};

apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export const WithKeywords = () => {
4747
onAbort={() => {
4848
action("onAbort")();
4949
}}
50+
onReset={() => {
51+
action("onReset")();
52+
}}
5053
/>
5154
);
5255
};
@@ -91,6 +94,9 @@ export const WithIcons = () => {
9194
onAbort={() => {
9295
action("onAbort")();
9396
}}
97+
onReset={() => {
98+
action("onReset")();
99+
}}
94100
/>
95101
);
96102
};
@@ -134,6 +140,9 @@ export const WithUnits = () => {
134140
onAbort={() => {
135141
action("onAbort")();
136142
}}
143+
onReset={() => {
144+
action("onReset")();
145+
}}
137146
/>
138147
<InputField
139148
readOnly

apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ type CssValueInputProps = Pick<
267267
onChangeComplete: (event: ChangeCompleteEvent) => void;
268268
onHighlight: (value: StyleValue | undefined) => void;
269269
onAbort: () => void;
270+
onReset: () => void;
270271
icon?: ReactNode;
271272
showSuffix?: boolean;
272273
};
@@ -337,6 +338,7 @@ export const CssValueInput = ({
337338
getOptions = () => [],
338339
onHighlight,
339340
onAbort,
341+
onReset,
340342
disabled,
341343
["aria-disabled"]: ariaDisabled,
342344
fieldSizing,
@@ -376,6 +378,13 @@ export const CssValueInput = ({
376378
const { value } = event;
377379
const defaultProps = { altKey: false, shiftKey: false };
378380

381+
// We are resetting by setting the value to an empty string
382+
if (value.type === "intermediate" && value.value === "") {
383+
closeMenu();
384+
onReset();
385+
return;
386+
}
387+
379388
if (value.type !== "intermediate" && value.type !== "invalid") {
380389
// The value might be valid but not selected from the combo menu. Close the menu.
381390
closeMenu();

0 commit comments

Comments
 (0)