Commit ff9581ff authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix(ui): handle tabs component slot vs array prop conflict

The tabs component receives tabs either as an array prop (for simple
label-based tabs) or as a named slot (for custom tab button HTML).
Now it handles both patterns without crashing on count().
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 749c16b3
...@@ -4,27 +4,31 @@ ...@@ -4,27 +4,31 @@
]) ])
@php @php
$alpineId = 'tabs-' . \Illuminate\Support\Str::random(6); $tabsIsArray = is_array($tabs) && count($tabs) > 0;
$defaultTab = $active ?? (count($tabs) > 0 ? array_key_first($tabs) : ''); $defaultTab = $active ?? ($tabsIsArray ? array_key_first($tabs) : '');
@endphp @endphp
<div x-data="{ activeTab: '{{ $defaultTab }}' }" {{ $attributes }}> <div x-data="{ activeTab: '{{ $defaultTab }}' }" {{ $attributes }}>
{{-- Tab Navigation --}} {{-- Tab Navigation --}}
<div class="flex border-b border-[var(--color-border)] overflow-x-auto" role="tablist"> <div class="flex border-b border-[var(--color-border)] overflow-x-auto" role="tablist">
@foreach($tabs as $key => $label) @if($tabsIsArray)
<button @foreach($tabs as $key => $label)
type="button" <button
role="tab" type="button"
x-on:click="activeTab = '{{ $key }}'" role="tab"
:aria-selected="activeTab === '{{ $key }}'" x-on:click="activeTab = '{{ $key }}'"
:class="activeTab === '{{ $key }}' :aria-selected="activeTab === '{{ $key }}'"
? 'border-[var(--color-primary)] text-[var(--color-primary)]' :class="activeTab === '{{ $key }}'
: 'border-transparent text-[var(--color-text-muted)] hover:text-[var(--color-text-primary)] hover:border-[var(--color-border)]'" ? 'border-[var(--color-primary)] text-[var(--color-primary)]'
class="px-4 py-3 text-sm font-medium border-b-2 -mb-px transition-all duration-200 whitespace-nowrap focus:outline-none" : 'border-transparent text-[var(--color-text-muted)] hover:text-[var(--color-text-primary)] hover:border-[var(--color-border)]'"
> class="px-4 py-3 text-sm font-medium border-b-2 -mb-px transition-all duration-200 whitespace-nowrap focus:outline-none"
{{ $label }} >
</button> {{ $label }}
@endforeach </button>
@endforeach
@elseif(isset($tabs) && !is_array($tabs))
{{ $tabs }}
@endif
</div> </div>
{{-- Tab Panels --}} {{-- Tab Panels --}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment