- LaralCN-UI: shadcn-style Blade components and blocks you own · part 24 of 26
- Laravel
- Blade
- Livewire
- LaralCN-UI
LaralCN-UI contact blocks: forms as data, and a null that did nothing
LaralCN-UI has 18 contact blocks now, from contact forms to office locations with maps. The forms are arrays of fields rendered with the library's own inputs. Building them also showed that a prop set to null falls back to its default, which made a line in the navbar docs wrong since day one.
4 min read
LaralCN-UI has 18 contact blocks now, from contact forms to office locations with maps. The forms are arrays of fields rendered with the library's own inputs. Building them also showed that a prop set to null falls back to its default, which made a line in the navbar docs wrong since day one.
A form is a list of fields
The first nine blocks are mostly forms, short or long, some beside contact details, an image or a map. Writing each form by hand in each block would have meant 18 slightly different copies of the same label-and-input markup. Instead every form block takes fields, and one renderer turns each entry into the right component:
<x-ui.blocks.contact-05
heading="Talk to us"
:action="route('contact.store')"
:fields="[
['name' => 'name', 'label' => 'Name', 'type' => 'text', 'required' => true],
['name' => 'email', 'label' => 'Email', 'type' => 'email', 'required' => true],
['name' => 'topic', 'label' => 'Topic', 'type' => 'select', 'options' => ['sales' => 'Sales', 'support' => 'Support']],
['name' => 'message', 'label' => 'Message', 'type' => 'textarea'],
]"
email="hello@acme.test"
phone="+961 1 234 567"
/>
A text, email or tel field becomes x-ui.input, textarea becomes x-ui.textarea, select becomes x-ui.select, and radio groups use x-ui.radio, each with an x-ui.label. Nothing is styled by hand, so a change to the input component reaches every contact form. A width key puts two fields side by side from md up.
Laravel's form plumbing comes free
The blocks render inside a Laravel request, so they behave like a form you wrote yourself. action and method are props, and a plain HTML form only knows GET and POST, so anything else is spoofed:
// A plain form only knows GET and POST; anything else is spoofed with _method.
$verb = strtoupper($method);
$formMethod = $verb === 'GET' ? 'GET' : 'POST';
@csrf is added for anything except GET, and @method($verb) for anything beyond POST. There is also a csrf prop, default on, for the rare form that posts to a third-party service where Laravel's token means nothing.
Contact details render as real links. Email gets mailto:, and the phone number keeps its formatting on screen while the tel: link strips everything but digits and +, so +1 (555) 000-0000 dials. The number sits in dir="ltr", so it reads the right way round on Arabic pages.
Maps without a third party by default
Several Relume layouts show a map. Embedding Google Maps by default would mean every site using the block loads a third-party iframe on every visit, cookies included, before anyone asked for a map. So a map is a muted box with a pin icon until you pass an embed URL:
<x-ui.blocks.contact-08 map="https://www.google.com/maps/embed?pb=..." map-title="Our Beirut office" />
With map set it renders a lazy-loaded iframe with a title for screen readers. The "Get directions" links are plain links to a maps search for the address, which costs nothing until someone clicks.
The office switcher has no script
contact-17 and contact-18 list offices on one side; picking one shows its photo or map on the other. That is a tab interface, and I tried the library's tabs component first. It could not do this layout: its tab buttons are fixed pills with plain-text labels, and its panels always sit under the list, never beside it.
Each office is a visually hidden x-ui.radio instead, followed by its label and its panel, and peer-checked shows the matching panel. There is no JavaScript, and the list works with Tab and the arrow keys because radios already do. The cost is that radio names must be unique, so two copies of the block on one page need different id props.
A null that never worked
The field arrays have optional extras, such as the terms checkbox. While testing I passed :terms="null" to remove it, and the checkbox stayed. The reason is in how Laravel compiles @props:
$$__key = $$__key ?? $__value;
That ?? treats an explicit null exactly like a missing prop, so it falls back to the default. false is the value that works, because the blocks check @if ($terms).
The awkward part was what came next. The navbar blocks' usage comments said :menu-label="null" removes the dropdown. It never did. Four navbars carried that line, and the docs page prints those comments as the usage example, so anyone who followed the docs got a dropdown they had asked to remove. The comments now say false, and the contact blocks document false from the start.
Where it is
composer require --dev safi/laralcn-ui
php artisan ui:init
php artisan ui:add-block contact-06
That installs the block plus the input, textarea, select, radio, checkbox, label and button components it uses. Previews: https://laralcn-ui.abdulkadersafi.com/blocks, with Arabic previews under /ar/blocks. Source: https://github.com/Abdulkader-Safi/LaralCN-UI. MIT licensed.
Next: ten FAQ blocks, filled from an array through the accordion's named slots.
Last updated 1 Dec 2026 · filed under Laravel, blade, livewire, laralcn-ui