-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I change the arrow in the select to an inline SVG #859
Labels
Comments
Good idea :) |
@astridx I found a way to make it <div
x-data="{
init() {
let choices = new Choices(this.$refs.select, {
removeItemButton: true, // not relevant
placeholder: true, // not relevant
allowHTML: false, // not relevant
});
},
appendIcon() {
const iconContainer = document.createElement('div');
iconContainer.classList.add('dropdown-icon');
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('width', '20');
svg.setAttribute('height', '20');
svg.setAttribute('viewBox', '0 0 20 20');
svg.setAttribute('fill', 'currentColor');
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
path.setAttribute('d', 'M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z');
svg.appendChild(path);
iconContainer.appendChild(svg);
this.$refs.select.parentNode.parentNode.appendChild(iconContainer);
}
}"
x-init="init(); appendIcon();"
class="w-full"
>
<select
name="{{$name}}@if($multiple)[]@endif"
id="{{$name}}-id"
x-ref="select"
@if($disabled) disabled @endif
@if($multiple) multiple @endif
>
@foreach($options as $k => $v)
<option value="{{ $k }}" {{ in_array($k, $selectedValueArray) ? 'selected' : '' }}>{{ $v }}</option>
@endforeach
</select>
</div> And I added inside my app.css .choices[data-type*=select-one] > .dropdown-icon {
@apply absolute top-1/2 right-2 transform -translate-y-1/2 text-shade-500 dark:text-shade-400
}
.choices[data-type*=select-multiple] > .dropdown-icon {
@apply hidden
} Hope it will help someone ✨ appendIcon() {
const iconContainer = document.createElement('div');
iconContainer.classList.add('custom-icon');
iconContainer.innerHTML = `
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
<path d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z"/>
</svg>`;
this.$refs.select.parentNode.parentNode.appendChild(iconContainer);
} but the backticks created a bug in my html page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
I can't figure out how I can change the dropdown arrow to an inline SVG .
Describe the solution you'd like
I like to use inline SVG for icons.
Describe alternatives you've considered
I know, that I can change it via CSS.
Additional context
Add any other context or screenshots about the feature request here.
This is my code as far.
Now I would like to put the star in the place of the arrow.
The text was updated successfully, but these errors were encountered: