Compare commits

...

5 Commits

Author SHA1 Message Date
bymyself
a842be2871 fix: correct createMockWidget calls in placeholder tests
The placeholder tests were calling createMockWidget with two positional
args (value, options) but the function accepts a single object arg. The
second argument was silently ignored, causing tests to fail. Also adds
explicit generic type to fix TypeScript narrowing errors.
2026-03-12 12:33:57 -07:00
bymyself
9ba77af763 style: fix formatting in ComboWidget tests
Amp-Thread-ID: https://ampcode.com/threads/T-019c7a94-a709-7773-b282-458d6bcb9e41
2026-03-12 12:27:51 -07:00
bymyself
8e516fd126 fix: guard against undefined values in _displayValue and inline hasEmptyOptions
Amp-Thread-ID: https://ampcode.com/threads/T-019c7a79-53f0-7329-8935-5b43637194c5
2026-03-12 12:27:51 -07:00
bymyself
cbe1744e3d fix: address code review feedback
- Fix widget value set to placeholder instead of empty string
- Eliminate duplicate rawValues resolution
- Fix ellipsis formatting and Vue props destructuring
- Add test for undefined placeholder edge case

Amp-Thread-ID: https://ampcode.com/threads/T-019c2c7e-2ac1-7114-9147-b41e6334faa9
2026-03-12 12:27:51 -07:00
bymyself
2fcb79dda8 feat: add placeholder support for empty combo widgets
Add placeholder field to combo widget schema and rendering:
- Add placeholder to zComboInputOptions in nodeDefSchema.ts
- Add placeholder to IWidgetOptions in widgets.ts
- Update ComboWidget._displayValue to show placeholder when values empty
- Update useComboWidget.ts to pass placeholder to widget options

When a combo widget has an empty options list and a placeholder is defined,
the placeholder text will be displayed instead of an empty dropdown.

Amp-Thread-ID: https://ampcode.com/threads/T-019c2bd5-472a-73a1-842b-4e05cba5d12c
2026-03-12 12:27:51 -07:00
7 changed files with 130 additions and 19 deletions

View File

@@ -1057,6 +1057,58 @@ describe('ComboWidget', () => {
expect(widget.canDecrement()).toBe(false)
})
it('should display placeholder text when values list is empty and placeholder is provided', () => {
widget = new ComboWidget(
createMockWidgetConfig({
name: 'ckpt_name',
value: '',
options: {
values: [],
placeholder:
'No models found in ComfyUI/models/checkpoints folder...'
}
}),
node
)
expect(widget._displayValue).toBe(
'No models found in ComfyUI/models/checkpoints folder...'
)
})
it('should display normal value when values list is not empty even with placeholder', () => {
widget = new ComboWidget(
createMockWidgetConfig({
name: 'ckpt_name',
value: 'model.safetensors',
options: {
values: ['model.safetensors', 'other.safetensors'],
placeholder:
'No models found in ComfyUI/models/checkpoints folder...'
}
}),
node
)
expect(widget._displayValue).toBe('model.safetensors')
})
it('should not display placeholder when placeholder is undefined', () => {
widget = new ComboWidget(
createMockWidgetConfig({
name: 'ckpt_name',
value: '',
options: {
values: [],
placeholder: undefined
}
}),
node
)
expect(widget._displayValue).toBe('')
})
it('should throw error when values is null in getValues', () => {
widget = new ComboWidget(
createMockWidgetConfig({

View File

@@ -35,6 +35,17 @@ export class ComboWidget
override get _displayValue() {
if (this.computedDisabled) return ''
const { values: rawValues, placeholder } = this.options
const resolvedValues =
typeof rawValues === 'function' ? rawValues(this, this.node) : rawValues
if (resolvedValues) {
const valuesArray = toArray(resolvedValues)
if (valuesArray.length === 0 && placeholder) {
return placeholder
}
}
const getOptionLabel = this.options.getOptionLabel
if (getOptionLabel) {
try {
@@ -45,13 +56,8 @@ export class ComboWidget
}
}
const { values: rawValues } = this.options
if (rawValues) {
const values = typeof rawValues === 'function' ? rawValues() : rawValues
if (values && !Array.isArray(values)) {
return values[this.value]
}
if (resolvedValues && !Array.isArray(resolvedValues)) {
return resolvedValues[this.value]
}
return typeof this.value === 'number' ? String(this.value) : this.value
}

View File

@@ -348,4 +348,38 @@ describe('WidgetSelect Value Binding', () => {
expect(wrapper.findComponent(WidgetSelectDropdown).exists()).toBe(false)
})
})
describe('Empty options with placeholder', () => {
it('shows placeholder when options are empty', () => {
const widget = createMockWidget<string | undefined>({
value: '',
options: {
values: [],
placeholder: 'No models found in ComfyUI/models/checkpoints folder...'
}
})
const wrapper = mountComponent(widget, '')
const selectDefault = wrapper.findComponent(WidgetSelectDefault)
const select = selectDefault.findComponent(SelectPlus)
expect(select.props('placeholder')).toBe(
'No models found in ComfyUI/models/checkpoints folder...'
)
})
it('does not show placeholder when options exist', () => {
const widget = createMockWidget<string | undefined>({
value: 'option1',
options: {
values: ['option1', 'option2'],
placeholder: 'No models found'
}
})
const wrapper = mountComponent(widget, 'option1')
const selectDefault = wrapper.findComponent(WidgetSelectDefault)
const select = selectDefault.findComponent(SelectPlus)
expect(select.props('placeholder')).toBeFalsy()
})
})
})

View File

@@ -49,7 +49,7 @@ interface Props {
widget: SimplifiedWidget<string | undefined>
}
const props = defineProps<Props>()
const { widget } = defineProps<Props>()
const modelValue = defineModel<string | undefined>({
default(props: Props) {
@@ -63,7 +63,7 @@ const transformCompatProps = useTransformCompatOverlayProps()
// Extract select options from widget options
const selectOptions = computed(() => {
const options = props.widget.options
const options = widget.options
if (options?.values && Array.isArray(options.values)) {
return options.values
@@ -75,9 +75,24 @@ const invalid = computed(
() => !!modelValue.value && !selectOptions.value.includes(modelValue.value)
)
const combinedProps = computed(() => ({
...filterWidgetProps(props.widget.options, PANEL_EXCLUDED_PROPS),
...transformCompatProps.value,
...(invalid.value ? { placeholder: `${modelValue.value}` } : {})
}))
const combinedProps = computed(() => {
const { placeholder: _, ...filteredOptions } = filterWidgetProps(
widget.options,
PANEL_EXCLUDED_PROPS
)
const baseProps = {
...filteredOptions,
...transformCompatProps.value
}
if (selectOptions.value.length === 0 && widget.options?.placeholder) {
return { ...baseProps, placeholder: widget.options.placeholder }
}
if (invalid.value) {
return { ...baseProps, placeholder: `${modelValue.value}` }
}
return baseProps
})
</script>

View File

@@ -163,10 +163,11 @@ describe('useComboWidget', () => {
expect(mockNode.addWidget).toHaveBeenCalledWith(
'combo',
'inputName',
undefined,
'',
expect.any(Function),
expect.objectContaining({
values: []
values: [],
placeholder: undefined
})
)
expect(widget).toBe(mockWidget)

View File

@@ -207,10 +207,11 @@ const addComboWidget = (
const widget = node.addWidget(
'combo',
inputSpec.name,
defaultValue,
defaultValue ?? '',
() => {},
{
values: inputSpec.options ?? []
values: inputSpec.options ?? [],
placeholder: inputSpec.placeholder
}
)

View File

@@ -99,7 +99,9 @@ export const zComboInputOptions = zBaseInputOptions.extend({
options: z.array(zComboOption).optional(),
remote: zRemoteWidgetConfig.optional(),
/** Whether the widget is a multi-select widget. */
multi_select: zMultiSelectOption.optional()
multi_select: zMultiSelectOption.optional(),
/** Placeholder text to display when the options list is empty. */
placeholder: z.string().optional()
})
const zIntInputSpec = z.tuple([z.literal('INT'), zIntInputOptions.optional()])