Skip to content

Commit 71ef7fe

Browse files
authored
fix applying Dropdown and MultiSelect selector styles (#1077)
1 parent 5322f6d commit 71ef7fe

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

.changeset/thin-horses-breathe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ensembleui/react-kitchen-sink": patch
3+
"@ensembleui/react-runtime": patch
4+
---
5+
6+
fix applying Dropdown and MultiSelect selector styles

apps/kitchen-sink/src/ensemble/screens/widgets.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -775,9 +775,9 @@ View:
775775
label: Choose multiple
776776
id: multiSelect1
777777
styles:
778-
multiSelectBackgroundColor: "aqua"
779-
multiSelectBorderWidth: 1
780-
multiSelectBorderColor: "lime"
778+
multiSelectBackgroundColor: "khaki"
779+
multiSelectBorderWidth: 4px
780+
multiSelectBorderColor: "red"
781781
multiSelectPadding: 10px
782782
multiSelectMaxWidth: 200px
783783
backgroundColor: "yellow"
@@ -802,6 +802,7 @@ View:
802802
- label: Option 3
803803
value: option3
804804
- Dropdown:
805+
id: myDropdown123
805806
label: Simple
806807
hintText: Hint Text
807808
styles:
@@ -810,6 +811,8 @@ View:
810811
dropdownPadding: 10px
811812
dropdownMaxWidth: 200px
812813
dropdownMinHeight: 50px
814+
dropdownBackgroundColor: "red"
815+
backgroundColor: "yellow"
813816
items:
814817
- label: Option 1
815818
value: 1
@@ -835,6 +838,9 @@ View:
835838
- Dropdown:
836839
value: 11
837840
label: With item template
841+
styles:
842+
dropdownBackgroundColor: aqua
843+
backgroundColor: purple
838844
labelStyle:
839845
color: green
840846
fontSize: 20

packages/runtime/src/shared/styles.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as Icons from "@mui/icons-material";
22
import type { SvgIconComponent } from "@mui/icons-material";
33
import { get, isInteger } from "lodash-es";
4-
import React from "react";
5-
import { TextAlignment } from "./styleSchema";
4+
import type React from "react";
5+
import type { TextAlignment } from "./styleSchema";
66

77
type Color = number | string;
88

@@ -105,6 +105,7 @@ export const getComponentStyles = (
105105
name: string,
106106
styles?: React.CSSProperties,
107107
returnAsString = true,
108+
addImportant = false,
108109
): string | React.CSSProperties => {
109110
const styleNames = Object.keys(styles || {}).filter((key) =>
110111
key.startsWith(name),
@@ -120,8 +121,11 @@ export const getComponentStyles = (
120121
// eslint-disable-next-line prefer-named-capture-group
121122
.replace(/([a-z])([A-Z])/g, "$1-$2")
122123
.toLowerCase(); // convert camelCase to kebab-case
123-
result += `${cssProperty}: ${styleValue};`;
124-
res = { ...res, [cssProperty]: styleValue };
124+
result += `${cssProperty}: ${styleValue}${addImportant ? " !important" : ""};`;
125+
res = {
126+
...res,
127+
[cssProperty]: `${styleValue}${addImportant ? " !important" : ""}`,
128+
};
125129
}
126130
});
127131

packages/runtime/src/widgets/Form/Dropdown.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const DropdownRenderer = (
7272
return (
7373
<>
7474
{menu}
75-
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
75+
{/* eslint-disable-next-line jsx-a11y/no-static-element-interactions */}
7676
<div
7777
onMouseDown={(e) => {
7878
e.preventDefault();
@@ -236,7 +236,7 @@ const Dropdown: React.FC<DropdownProps> = (props) => {
236236
height: unset !important;
237237
}
238238
.${id}_input .ant-select-selector {
239-
${getComponentStyles("dropdown", values?.styles) as string}
239+
${getComponentStyles("dropdown", values?.styles, true, true) as string}
240240
}
241241
.ant-select-item.ant-select-item-option.${id}_option[aria-selected="true"] {
242242
${

packages/runtime/src/widgets/Form/MultiSelect.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ const MultiSelect: React.FC<MultiSelectProps> = (props) => {
286286
<>
287287
<style>{`
288288
.${id}_input .ant-select-selector {
289-
${getComponentStyles("multiSelect", values?.styles) as string}
289+
${getComponentStyles("multiSelect", values?.styles, true, true) as string}
290290
}
291291
.ant-select-item.ant-select-item-option.${id}_option[aria-selected="true"]
292292
{

0 commit comments

Comments
 (0)