We have some custom components which can be used for user input (CustomSelect, SegmentedControl, CustomCheckbox, etc).
In some cases, these internally use the semantic html tag like radiogroup or select, but in some cases, the markup is completely written using div and span elements and accessibility is provided using aria attributes. For such implementations, is there a way to associate a label element to them, to make them behave like native form inputs wrt label behaviour, or better, is there a way to get them treated like native form inputs?
Things that come to mind:
- use a visually hidden html form element which somehow wraps the custom, and somehow hide its semantics.
- fieldset and legend might make sense in some cases
- using javascript to imitate label functionality
Are there any existing patterns for this?