If a set of buttons (or labels) set the value of an input with a different value each, what roles and arias should they possess?
In this scenario the input can also be inserted/edited by the user manually.
So they would work similar to a set of radio buttons with an “Other, insert below” option.
Here is an example:
$("label").on("click", (event) => {
const text = event.target.textContent;
$("#text").val(text);
});
label {
display: block;
cursor: pointer;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<form action="javascript:void(0)">
<label for="text">Text A</label>
<label for="text">Text B</label>
<label for="text">Text C</label>
<input type="text" id="text" />
</form>
I’ve used labels in this case, so that the user can make edits to the selected with the least amount of actions possible. Labels also signify the link between the elements.
Should I add aria-controls
, should I use button
s, should I change the overwrite the role
s?