# Components Reference Complete API reference for all form components in the Admin package, including prop documentation, validation rules, authorization integration, and accessibility notes. ## Overview All form components in Core PHP: - Wrap Flux UI components with additional features - Support authorization via `canGate` and `canResource` props - Include ARIA accessibility attributes - Work seamlessly with Livewire - Follow consistent naming conventions ## Input Text input with various types and authorization support. ### Basic Usage ```blade ``` ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `id` | string | **required** | Unique identifier for the input | | `label` | string | `null` | Label text displayed above input | | `helper` | string | `null` | Helper text displayed below input | | `canGate` | string | `null` | Gate/policy ability to check | | `canResource` | mixed | `null` | Resource to check ability against | | `instantSave` | bool | `false` | Use `wire:model.live.debounce.500ms` | | `type` | string | `'text'` | Input type (text, email, password, number, etc.) | | `placeholder` | string | `null` | Placeholder text | | `disabled` | bool | `false` | Disable the input | | `readonly` | bool | `false` | Make input read-only | | `required` | bool | `false` | Mark as required | | `min` | number | `null` | Minimum value (for number inputs) | | `max` | number | `null` | Maximum value (for number inputs) | | `maxlength` | number | `null` | Maximum character length | ### Authorization Example ```blade {{-- Input disabled if user cannot update the post --}} ``` ### Type Variants ```blade {{-- Text input --}} {{-- Email input --}} {{-- Password input --}} {{-- Number input --}} {{-- Date input --}} {{-- URL input --}} ``` ### Instant Save Mode ```blade {{-- Saves with 500ms debounce --}} ``` ### Accessibility The component automatically: - Associates label with input via `id` - Links error messages with `aria-describedby` - Sets `aria-invalid="true"` when validation fails - Includes helper text in accessible description --- ## Textarea Multi-line text input with authorization support. ### Basic Usage ```blade ``` ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `id` | string | **required** | Unique identifier | | `label` | string | `null` | Label text | | `helper` | string | `null` | Helper text | | `canGate` | string | `null` | Gate/policy ability to check | | `canResource` | mixed | `null` | Resource for ability check | | `instantSave` | bool | `false` | Use live debounced binding | | `rows` | number | `3` | Number of visible rows | | `placeholder` | string | `null` | Placeholder text | | `disabled` | bool | `false` | Disable the textarea | | `maxlength` | number | `null` | Maximum character length | ### Authorization Example ```blade ``` ### With Character Limit ```blade ``` --- ## Select Dropdown select with authorization support. ### Basic Usage ```blade Draft Published Archived ``` ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `id` | string | **required** | Unique identifier | | `label` | string | `null` | Label text | | `helper` | string | `null` | Helper text | | `canGate` | string | `null` | Gate/policy ability to check | | `canResource` | mixed | `null` | Resource for ability check | | `instantSave` | bool | `false` | Use live binding | | `placeholder` | string | `null` | Placeholder option text | | `disabled` | bool | `false` | Disable the select | | `multiple` | bool | `false` | Allow multiple selections | ### Authorization Example ```blade @foreach($categories as $category) {{ $category->name }} @endforeach ``` ### With Placeholder ```blade United States United Kingdom Canada ``` ### Multiple Selection ```blade @foreach($tags as $tag) {{ $tag->name }} @endforeach ``` --- ## Checkbox Single checkbox with authorization support. ### Basic Usage ```blade ``` ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `id` | string | **required** | Unique identifier | | `label` | string | `null` | Label text (displayed inline) | | `helper` | string | `null` | Helper text below checkbox | | `canGate` | string | `null` | Gate/policy ability to check | | `canResource` | mixed | `null` | Resource for ability check | | `instantSave` | bool | `false` | Use live binding | | `disabled` | bool | `false` | Disable the checkbox | | `value` | string | `null` | Checkbox value (for arrays) | ### Authorization Example ```blade ``` ### With Helper Text ```blade ``` ### Checkbox Group ```blade
Notifications
``` --- ## Toggle Switch-style toggle with authorization support. ### Basic Usage ```blade ``` ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `id` | string | **required** | Unique identifier | | `label` | string | `null` | Label text (displayed to the left) | | `helper` | string | `null` | Helper text below toggle | | `canGate` | string | `null` | Gate/policy ability to check | | `canResource` | mixed | `null` | Resource for ability check | | `instantSave` | bool | `false` | Use live binding | | `disabled` | bool | `false` | Disable the toggle | ### Authorization Example ```blade ``` ### Instant Save ```blade {{-- Toggle that saves immediately --}} ``` ### With Helper ```blade ``` --- ## Button Action button with variants and authorization support. ### Basic Usage ```blade Save Changes ``` ### Props | Prop | Type | Default | Description | |------|------|---------|-------------| | `variant` | string | `'primary'` | Button style variant | | `type` | string | `'submit'` | Button type (submit, button, reset) | | `canGate` | string | `null` | Gate/policy ability to check | | `canResource` | mixed | `null` | Resource for ability check | | `disabled` | bool | `false` | Disable the button | | `loading` | bool | `false` | Show loading state | ### Variants ```blade {{-- Primary (default) --}} Primary {{-- Secondary --}} Secondary {{-- Danger --}} Delete {{-- Ghost --}} Cancel ``` ### Authorization Example ```blade {{-- Button disabled if user cannot delete --}} Delete Post ``` ### With Loading State ```blade Save Saving... ``` ### As Link ```blade Cancel ``` --- ## Authorization Props Reference All form components support authorization through consistent props. ### How Authorization Works When `canGate` and `canResource` are provided, the component checks if the authenticated user can perform the specified ability on the resource: ```php // Equivalent PHP check auth()->user()?->can($canGate, $canResource) ``` If the check fails, the component is **disabled** (not hidden). ### Props | Prop | Type | Description | |------|------|-------------| | `canGate` | string | The ability/gate name to check (e.g., `'update'`, `'delete'`, `'publish'`) | | `canResource` | mixed | The resource to check the ability against (usually a model instance) | ### Examples **Basic Policy Check:** ```blade ``` **Multiple Components with Same Auth:** ```blade @php $canEdit = auth()->user()?->can('update', $post); @endphp Save ``` **Combining with Blade Directives:** ```blade @can('update', $post) Save @else

You do not have permission to edit this post.

@endcan ``` ### Defining Policies ```php id === $post->author_id || $user->hasRole('editor'); } public function delete(User $user, Post $post): bool { return $user->hasRole('admin'); } public function publish(User $user, Post $post): bool { return $user->hasPermission('posts.publish') && $post->status === 'draft'; } } ``` --- ## Accessibility Notes ### ARIA Attributes All components automatically include appropriate ARIA attributes: | Attribute | Usage | |-----------|-------| | `aria-labelledby` | Links to label element | | `aria-describedby` | Links to helper text and error messages | | `aria-invalid` | Set to `true` when validation fails | | `aria-required` | Set when field is required | | `aria-disabled` | Set when field is disabled | ### Label Association Labels are automatically associated with inputs via the `id` prop: ```blade {{-- Renders as: --}} Email Address ``` ### Error Announcements Validation errors are linked to inputs and announced to screen readers: ```blade {{-- Component renders error with aria-describedby link --}} {{-- Screen readers announce: "Email is required" --}} ``` ### Focus Management - Tab order follows visual order - Focus states are clearly visible - Error focus moves to first invalid field ### Keyboard Support | Component | Keyboard Support | |-----------|------------------| | Input | Standard text input | | Textarea | Standard multiline | | Select | Arrow keys, Enter, Escape | | Checkbox | Space to toggle | | Toggle | Space to toggle, Arrow keys | | Button | Enter/Space to activate | --- ## Validation Integration ### Server-Side Validation Components automatically display Laravel validation errors: ```php // In Livewire component protected array $rules = [ 'title' => 'required|max:255', 'content' => 'required', 'status' => 'required|in:draft,published', ]; public function save(): void { $this->validate(); // Errors automatically shown on components } ``` ### Real-Time Validation ```php public function updated($propertyName): void { $this->validateOnly($propertyName); } ``` ```blade {{-- Shows validation error as user types --}} ``` ### Custom Error Messages ```php protected array $messages = [ 'title.required' => 'Please enter a post title.', 'content.required' => 'Post content cannot be empty.', ]; ``` --- ## Complete Form Example ```blade
{{-- Title --}} {{-- Slug with instant save --}} {{-- Content --}} {{-- Category --}} @foreach($categories as $category) {{ $category->name }} @endforeach {{-- Status --}} Draft Published Archived {{-- Featured toggle --}} {{-- Newsletter checkbox --}} {{-- Actions --}}
Save Changes Cancel @can('delete', $post) Delete @endcan
``` ## Learn More - [Form Components Guide](/packages/admin/forms) - [Authorization](/packages/admin/authorization) - [Creating Admin Panels](/packages/admin/creating-admin-panels) - [Livewire Modals](/packages/admin/modals)