htmlstreamofficial / preline

Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.
https://preline.co
Other
4.9k stars 309 forks source link

Bug | Select | Compomemnt #439

Closed naumcei closed 1 month ago

naumcei commented 3 months ago

Summary

There is a bug on dropdwon select, Please note that the removeOption is calling the setOption

Steps to Reproduce

In latest version 2.4.1

public removeOption(values: string | string[]) {
    const removeOption = (val: string, isArray = false) => {
        const hasOption = !!this.selectOptions.some(
            (el: ISingleOption) => el.val === val,
        );

        if (hasOption) {
            this.removeSelectOption(val, isArray);
            this.destroyOption(val);
            this.destroyOriginalOption(val);

            if (this.value === val) {
                this.value = null;

                this.eraseToggleTitle();
                this.eraseToggleIcon();
            }
        }
    };

    if (Array.isArray(values)) {
        values.forEach((val) => {
            removeOption(val, this.isMultiple);
        });
    } else {
        removeOption(values, this.isMultiple);
    }

    this.setNewValue();
}

The is a bug in the function

private setNewValue() {
    if (this.mode === 'tags') {
        this.setTagsItems();
    } else {
        console.log();

        if (this.value.length)
            this.toggleTextWrapper.innerHTML = this.stringFromValue();
        else this.toggleTextWrapper.innerHTML = this.placeholder;
    }
}
preline.js?v=d33b9117:4419 Uncaught TypeError: Cannot read properties of null (reading 'length')
    at _HSSelect.setNewValue (preline.js?v=d33b9117:4419:22)
    at _HSSelect.removeOption (preline.js?v=d33b9117:4613:10)

Demo Link

\

Expected Behavior

No response

Actual Behavior

No response

Screenshots

No response

olegpix commented 1 month ago

@naumcei Hi, Thanks for reporting this. We fixed it in version 2.5.0, please update. Let us know if you have any issues with this.