{% from "admin/components/icons.html" import icon %} {# Select, ported from shadcn/ui -- a styled trigger and listbox for a static choice list. A hidden input carries the posted value, so the model layer never has to know it came from anything but a plain . Args: name form field name options [(value, label), ...] selected the currently selected value, compared with `==` against each option's value placeholder shown when nothing is selected disabled bool #} {% macro select(name, options, selected=none, placeholder=_("Select…"), disabled=false, compact=false) %} {% set selected_label = namespace(value=none) %} {% for value, label in options %} {% if value == selected %}{% set selected_label.value = label %}{% endif %} {% endfor %} {# The initial label rides in as a data attribute and is read back with $el.dataset, never interpolated into the x-data expression: tojson emits a raw double quote, which closed this attribute early and left Alpine parsing a truncated expression, so every select on the page failed to initialise. #} {# Focus stays on the trigger and the arrow keys move a highlight it reports through aria-activedescendant, rather than moving real focus into the list. That means one focusable element instead of one per option, so the options are tabindex="-1" and Tab leaves the control rather than walking every choice. #}
{# Portalled to , as Radix does -- see the relation combobox in ui/field.html. A select in a table cell is the case that needs it: the row clips anything taller than itself. #}
{% endmacro %} {% macro select_script() %} {% endmacro %}