Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit c70f07b

Browse files
committed
wip
1 parent 5e0590d commit c70f07b

File tree

9 files changed

+85
-37
lines changed

9 files changed

+85
-37
lines changed

dist/form-components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/form-components.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"/form-components.js":"/form-components.js?id=463675fb6a026cc94be2"}
1+
{"/form-components.js":"/form-components.js?id=e9ea2b6e046331699d23"}

resources/js/components/custom-select.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ export default function customSelect(state) {
4747

4848
this.updateDisplay(this.value);
4949

50-
$watch('value', value => this.updateDisplay(value));
50+
$watch('value', value => {
51+
this.updateDisplay(value);
52+
53+
if (this.filterable) {
54+
this.refreshOptionsIfNeeded();
55+
}
56+
});
5157
$watch('query', value => this.filter(value));
5258
$watch('wireFilter', () => {
5359
this.$nextTick(() => {
@@ -342,12 +348,27 @@ export default function customSelect(state) {
342348
this.open = ! this.open;
343349

344350
if (this.open) {
345-
this.$nextTick(() => this.positionMenu());
351+
this.$nextTick(() => {
352+
this.positionMenu();
353+
this.refreshOptionsIfNeeded();
354+
});
355+
346356
this.highlightSelectedOption();
347357
this[this.filterable ? 'focusFilter' : 'focusMenu']();
348358
}
349359
},
350360

361+
// Note: this seems like a dirty hack for when wire:model is used on the select
362+
// and probably should be revisited in the future to see how we can
363+
// prevent each option from losing its id and data-index attributes.
364+
refreshOptionsIfNeeded() {
365+
const children = this.optionChildren();
366+
367+
if (! children.length || ! children[0].getAttribute('id')) {
368+
this.options = this.parseOptions();
369+
}
370+
},
371+
351372
positionMenu() {
352373
this.$refs.container.classList.remove('custom-menu-top');
353374

resources/views/components/inputs/custom-select-option.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<li @unless ($disabled)
1+
<li @unless ($disabled || $isGroup)
22
x-on:mouseenter="onMouseEnter({{ $optionValue() }})"
33
x-on:mouseleave="selected = null; currentIndex = -1"
44
x-on:click="choose({{ $optionValue() }})"
Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,2 @@
1-
<div class="form-text-container {{ $maxWidth }}">
2-
@include('form-components::partials.leading-addons')
3-
4-
<select name="{{ $name }}"
5-
@if ($id) id="{{ $id }}" @endif
6-
@if ($multiple) multiple @endif
7-
8-
@if ($hasErrorsAndShow($name))
9-
aria-invalid="true"
10-
11-
@if (! $attributes->offsetExists('aria-describedby'))
12-
aria-describedby="{{ $id }}-error"
13-
@endif
14-
@endif
15-
16-
{{ $attributes->merge(['class' => $inputClass()]) }}
17-
>
18-
{{ $slot }}
19-
20-
@foreach (app('fc-timezone')->only($only)->all() as $region => $regionTimezones)
21-
<optgroup label="{{ $region }}">
22-
@foreach ($regionTimezones as $key => $display)
23-
<option value="{{ $key }}"@if ($isSelected($key)) selected @endif>{{ $display }}</option>
24-
@endforeach
25-
</optgroup>
26-
@endforeach
27-
</select>
28-
29-
@include('form-components::partials.trailing-addons')
30-
</div>
1+
@includeWhen(! $useCustomSelect, 'form-components::partials.timezone-select-native')
2+
@includeWhen($useCustomSelect, 'form-components::partials.timezone-select-custom')
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<x-custom-select :filterable="$filterable" :optional="$optional" :placeholder="$placeholder" :multiple="$multiple" {{ $attributes }}>
2+
{{ $slot }}
3+
4+
@foreach (app('fc-timezone')->only($only)->all() as $region => $regionTimezones)
5+
<x-custom-select-option is-group>{{ $region }}</x-custom-select-option>
6+
7+
@foreach ($regionTimezones as $key => $display)
8+
<x-custom-select-option wire:key="tz-{{ $key }}" :option="['value' => $key, 'text' => $display]" />
9+
@endforeach
10+
@endforeach
11+
</x-custom-select>

0 commit comments

Comments
 (0)