Better combo menu width handling
This commit is contained in:
@@ -41,6 +41,7 @@ export default class ComfyComboNode extends ComfyWidgetNode<string> {
|
|||||||
firstLoad: Writable<boolean>;
|
firstLoad: Writable<boolean>;
|
||||||
lightUp: Writable<boolean>;
|
lightUp: Writable<boolean>;
|
||||||
valuesForCombo: Writable<any[]>; // Changed when the combo box has values.
|
valuesForCombo: Writable<any[]>; // Changed when the combo box has values.
|
||||||
|
maxLabelWidthChars: number = 0;
|
||||||
|
|
||||||
constructor(name?: string) {
|
constructor(name?: string) {
|
||||||
super(name, "A")
|
super(name, "A")
|
||||||
@@ -77,13 +78,17 @@ export default class ComfyComboNode extends ComfyWidgetNode<string> {
|
|||||||
else
|
else
|
||||||
formatter = (value: any) => `${value}`;
|
formatter = (value: any) => `${value}`;
|
||||||
|
|
||||||
|
this.maxLabelWidthChars = 0;
|
||||||
|
|
||||||
let valuesForCombo = []
|
let valuesForCombo = []
|
||||||
|
|
||||||
try {
|
try {
|
||||||
valuesForCombo = this.properties.values.map((value, index) => {
|
valuesForCombo = this.properties.values.map((value, index) => {
|
||||||
|
const label = formatter(value);
|
||||||
|
this.maxLabelWidthChars = Math.max(this.maxLabelWidthChars, label.length)
|
||||||
return {
|
return {
|
||||||
value,
|
value,
|
||||||
label: formatter(value),
|
label,
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -91,9 +96,11 @@ export default class ComfyComboNode extends ComfyWidgetNode<string> {
|
|||||||
catch (err) {
|
catch (err) {
|
||||||
console.error("Failed formatting!", err)
|
console.error("Failed formatting!", err)
|
||||||
valuesForCombo = this.properties.values.map((value, index) => {
|
valuesForCombo = this.properties.values.map((value, index) => {
|
||||||
|
const label = `${value}`
|
||||||
|
this.maxLabelWidthChars = Math.max(this.maxLabelWidthChars, label.length)
|
||||||
return {
|
return {
|
||||||
value,
|
value,
|
||||||
label: `${value}`,
|
label,
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -169,7 +169,7 @@
|
|||||||
on:select={(e) => handleSelect(e.detail.index)}
|
on:select={(e) => handleSelect(e.detail.index)}
|
||||||
on:blur
|
on:blur
|
||||||
on:filter={onFilter}>
|
on:filter={onFilter}>
|
||||||
<div class="comfy-select-list" slot="list" let:filteredItems>
|
<div class="comfy-select-list" slot="list" let:filteredItems style:--maxLabelWidth={node.maxLabelWidthChars || 100}>
|
||||||
{#if filteredItems.length > 0}
|
{#if filteredItems.length > 0}
|
||||||
{@const itemSize = isMobile ? 50 : 25}
|
{@const itemSize = isMobile ? 50 : 25}
|
||||||
{@const itemsToShow = isMobile ? 10 : 30}
|
{@const itemsToShow = isMobile ? 10 : 30}
|
||||||
@@ -286,7 +286,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.comfy-select-list {
|
.comfy-select-list {
|
||||||
width: 30rem;
|
--maxLabelWidth: 100;
|
||||||
|
font-size: 14px;
|
||||||
|
width: min(calc((var(--maxLabelWidth) + 10) * 1ch), 50vw);
|
||||||
color: var(--item-color);
|
color: var(--item-color);
|
||||||
|
|
||||||
> :global(.virtual-list-wrapper) {
|
> :global(.virtual-list-wrapper) {
|
||||||
|
|||||||
Reference in New Issue
Block a user