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

Additional methods for advanced select #389

Open Gordi90 opened 5 months ago

Gordi90 commented 5 months ago

Summary

Additional advanced select methods to support frameworks

Detailed Description

I've run into a couple of issues when I wanted to create an Angular component based on the advanced select. As I was searching for a solution I've read multiple issues in this repository and studied the source of the advanced select. I realized, that right now there are about 20 issues that somehow involves the advanced select and different framework issues, mostly about:

The maintainers reasoning is perfectly understandable: It would be impossible to provide support for all frameworks. There was an update for the advanced select's documentation as well. However a gap remains between the creators and users (or customers for preline pro).

I suggest making it perfectly clear in the documentation, that:

My second advice is the request itself: there should be methods to manipulate the state and value for the advanced select. I understand, that preline plugins use vanilla JS, but this approach with the static init script makes it extremely hard to create a custom component in any framework. There are numerous issues about conditional rendering and people are trying to guess when to call

window.HSStaticMethods.autoInit(['select']);

in their components. After a couple of days I still have to find out how to fix every state change in my component. It would help a lot for anyone using any framework, if there would be a method to change the selected value for example. Right now, if you want to change it, the only way to keep the advanced select's inner state consistent is to find the div with the value, and "click" on it:

    const optionElement = document.querySelector(
      `div[data-value="${this.selectedItem.val}"]`
    ) as HTMLDivElement;
    if (optionElement) {
      optionElement.click();
    }

But this way I still cannot reset the state to "Select option..." because there is no way to do so, even for the enduser. It would be highly beneficial if there were such setter methods, so:

Use Cases

Custom framework components, like an entity editor.