germsvel / phoenix_test

PhoenixTest provides a unified way of writing feature tests -- regardless of whether you're testing LiveView pages or static (non-LiveView) pages.
https://hex.pm/packages/phoenix_test
MIT License
181 stars 23 forks source link

fill_in without a label #132

Closed andrewtimberlake closed 1 month ago

andrewtimberlake commented 1 month ago

Sometimes a form element doesn’t have a label: CleanShot 2024-10-01 at 12 01 15@2x

It would be nice to be able to use fill_in("model[field]", nil, with: "text") or similar.

germsvel commented 1 month ago

@andrewtimberlake in those cases, it's good to have a hidden label (at least as far as I understand accessibility, but I'm not an expert). So what I'd recommend is have a hidden label (with tailwind you could add sr-only class.)

This is from mdn docs:

The label text is not only visually associated with its corresponding text input; it is programmatically associated with it too. This means that, for example, a screen reader will read out the label when the user is focused on the form input, making it easier for an assistive technology user to understand what data should be entered.

That would allow you to target it with fill_in("Domain", with: "text")

andrewtimberlake commented 1 month ago

Thanks, that’s what I ended up doing ;-)