Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some way to find an element labelled by another #52

Open
avh4 opened this issue Feb 4, 2018 · 1 comment
Open

Some way to find an element labelled by another #52

avh4 opened this issue Feb 4, 2018 · 1 comment
Assignees

Comments

@avh4
Copy link

avh4 commented Feb 4, 2018

Split from #32 by request.

some way to find the input that's associated with a label that matched another selector. In this example, find the input associated with the "A" label, and not the other input (this should also work in cases where the input and the label aren't siblings):

div []
    [ label [ for "input-1" ] [ text "A" ]
    , label [ for "input-2" ] [ text "B" ]
    , input [ id "input-1" ] []
    , input [ id "input-2" ] []
    ]

Possible low-level API: (See also #51)

dom
    |> Query.find [ tag "label", text "A" ]
    |> Query.getAttribute "for"
    |> (\labelFor -> Query.find [ tag "input", id labelFor ] dom)

(I guess Query.getAttribute would probably have to return Result _ String or even Result _ (Maybe String) instead of String.)

Possible high-level API:

Query.find
    [ tag "input"
    , labelledBy [ tag "label", text "A" ]
    ]

Note that the solution should be usable both for the for attribute in label elements, and for aria-labelledby attribute on all elements.

@rtfeldman
Copy link
Collaborator

Related: #51

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

No branches or pull requests

2 participants