djibe / material

Material Design 2 for Bootstrap 4 (active fork of Daemonite Material)
https://djibe.github.io/material/
MIT License
68 stars 11 forks source link

Any way to make this work with select2? #10

Closed zelenij closed 4 years ago

zelenij commented 4 years ago

This is a great piece of work, my web site looks very material! One thing is missing - there are no searchable select box options. A third party plugin for JQery exists, but it doesn't play nice with this whole setup. Any ideas on how to fix it? https://select2.org/ - the resulting selects show up as "regular" bootstrap ones (or even plain ones, can't really tell). Kinda breaks the whole visual consistency of my forms...

justlevine commented 4 years ago

What specifically is the problem? Select2 works fine on my install...

zelenij commented 4 years ago

Well, the ones with select2 look different. Here is a screenshot for illustration - there are two selects side by side, the one on the left is unmodified, the one on the right is with select2. Note the rounded appearance of the frame etc.

image

justlevine commented 4 years ago

Ahh so its not that select2 doesnt work, its that it has its own css styles? Try googling select2 material themes and you should find a bunch of 3rd-party css files. Based on your screenshot this one seems like itl fit https://codepen.io/rpuga/pen/Baypwpr

zelenij commented 4 years ago

Well, I tried that, and I found the same link you shared. However, the end result was kinda ugly and not matching what you can see in codepen. I suspect it might be clashing with material design UI. Obviously, this probably can be debugged, but I was wondering if this is something other people have already figured out.

tbuyle commented 4 years ago

I use Select2 with Material (Daemonite version) with some CSS and it works ok.

Here is a GIST with my sccs : https://gist.github.com/tbuyle/4b6aa8c2fe7dfaea1103c0f7eb76fc1c

It's certainly not 100% perfect but it does the trick for me.

zelenij commented 4 years ago

@tbuyle I tried compiling your scss to CSS using a command line tool, but it failed :)

tbuyle commented 4 years ago

This SCSS depends on variables from Bootstrap and material and can not be compiled alone.

djibe commented 4 years ago

I'm working on it

djibe commented 4 years ago

Working on the default one. default

you will be able to set: theme: 'outlined' for this outlined

I have to do:

zelenij commented 4 years ago

Thanks! I knew it wasn't trivial :)

djibe commented 4 years ago

Hi @zelenij , here is a first version : https://gist.github.com/djibe/2f394a3c7e7eb2510a801cce976ad6f1 Standalone (don't import any Select2 css file). Don't set a theme or set it to 'outlined'

Optgroup is bugged Searchbox is ugly

djibe commented 4 years ago

Hi, I updated Gist with default, or theme 'outlined' and theme 'filled'. Can you test it ?

zelenij commented 4 years ago

Thank you @djibe, will give it a go and update

zelenij commented 4 years ago

To be honest, I don't see much difference - the only thing, select drop down looks more material:

image

I copied your gist into a css file and linked it to my site, I presume this is how it is supposed to be used?

Select2@4.1.0-beta.1 . Also tried 4.0.13, but actually looks ugly :)

djibe commented 4 years ago

Hi, don't import any other Select2 css. Use latest Select2. Set theme: 'outlined' (or 'filled') I updated Gist right now.

I'm nearly done with multiple select.

zelenij commented 4 years ago

I think it's better, but with filled theme the multi-select looks kinda dodgy:

image

djibe commented 4 years ago

I'm not done with Multiple version.

djibe commented 4 years ago

@zelenij Think I got it. See my gist. $(".js-example-basic-single").select2({ theme: "filled", placeholder: 'Fruit', width: '300px', multiple: true, // minimumResultsForSearch: Infinity / Hide search on single / });

Select2 width has to be set with JS.

For a simple single select, I use a minimum 200px width that don't have to be manually set. Tell me if you experience bugs.

zelenij commented 4 years ago

Visually looks better! I think there is a bug however:

image

I select the first item from the drop down. If I close the drop down it is not shown in the main area:

image

Selecting other items seems to work, so it is not consistent. Nothing in the error console.

If I switch to vanilla select2, it works as expected:

image

djibe commented 4 years ago

True. This is because I tested with a placeholder (so a first blank option). i'll try to fix it tonight.

djibe commented 4 years ago

@zelenij Updated gist. Hope it is final version :D Is it good for you ?

djibe commented 4 years ago

@zelenij Hi, is the latest Gist update good for you ?

zelenij commented 4 years ago

@djibe - sorry for not coming back earlier, was dealing with unrelated stuff. Looks fine now, thanks. Is there a way to control the height of the multi-select box? See how a single and multi-select ones differ here?

image

djibe commented 4 years ago

Hi @zelenij Normaly the filled theme is 56px height. I updated gist. You may try again.

zelenij commented 4 years ago

I don't see any difference to be honest. And looking at the latest commit in the gist, I see that the only change is the background image. Maybe you didn't push the rest of it? :)

djibe commented 4 years ago

You can use material-plugins.css to style select2. Set theme to "", "filled" or "outlined". Doc is on the way

djibe commented 4 years ago

Hi. You can use material-plugins.css from the dist folder and use Select2 as usual (don't set a theme, or set 'filled' or 'outlined')

zelenij commented 4 years ago

Thanks, will give it a try

djibe commented 4 years ago

Here it is: https://djibe.github.io/material/docs/4.5/plugins/select-select2/