Skip to content

Fix Select to render native <select> by default (#91)#160

Open
oegedijk wants to merge 1 commit intoAnswerDotAI:mainfrom
oegedijk:fix-select-native
Open

Fix Select to render native <select> by default (#91)#160
oegedijk wants to merge 1 commit intoAnswerDotAI:mainfrom
oegedijk:fix-select-native

Conversation

@oegedijk
Copy link
Copy Markdown

Fixes #91. +8 lines, one file.

Select currently always wraps <uk-select>. That means id/name land on the wrapper, not a form control, so native form submission and HTMX (hx_trigger="change", hx_include="#my_select") don't work.

Fix: when searchable/insertable aren't requested, just return fh.Select(..., cls='uk-select', id=id, name=name, **kwargs) and skip the web component.

if not (searchable or insertable):
    if id and not name: name = id
    return fh.Select(*option, cls=('uk-select', inp_cls), id=id, name=name, **kwargs)

The searchable/insertable path is untouched.

Tradeoff

The closed/styled appearance is the same — .uk-select CSS styles native <select> too (border, padding, chevron, focus). The difference shows up when you open the dropdown: native uses the OS picker instead of the FrankenUI-themed panel. If a user wants the themed panel they opt in with searchable=True.

Rich HTML inside <option> (e.g. Option(A(...))) won't render links in native — browsers only render text inside options. Nothing in the repo relies on this except the dashboard example where the A tags were cosmetic; the options still display fine.

When searchable/insertable aren't requested, skip the <uk-select> web
component and return a plain <select class="uk-select">. This makes
id/name land on a real form control and lets HTMX attributes pass
through unmodified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

monsterui Select not working when a switch or checkbox is present

2 participants