fix(form-elements): add focus-within focus styling#1646
Conversation
In the process of reviewing StackEng/StackOverflow#18700, we identified an issue with non-focusable elements styled to look like inputs with `.s-input` ([tag editor input for example](StackEng/StackOverflow#18700 (comment))). These elements will contain invisible or restyled input elements. We want to ensure that the elements with `.s-input` (or similar) receive focus styling when child elements are focused.
✅ Deploy Preview for stacks ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
giamir
left a comment
There was a problem hiding this comment.
Based on MDN definition the :focus-within CSS pseudo-class represents an element that is itself matched by the :focus pseudo-class or has a descendant that is matched by :focus. If I understand that correctly we can simply apply :focus-within and that would also take care of :focus.
Overall the changes are pretty simple and I am ok to merge them. I probably don't fully understand the creative ways we use those classes in Core though. See sidenote for more details. 🙂
Sidenote
Do we incentivize the use of s-input, s-checkbox, etc... classes to elements that are not in fact input, input type="checkbox", etc...?
If we do so we should have at least a use case example in the docs in my opinion documenting when that makes sense.
I am asking because an input type="checkbox" under regular circumstances would not have any focusable descendants and therefore there would not be a need to use :focus-within - In fact it would likely confuse the average reader unless there is at least a comment explaining why we use that over :focus.
This is more of a desire path situation. I wouldn't say that we explicitly incentivize the pattern of wrapping inputs in parents that include the input component class, but we have a few instances of it in Core (an example could be found on the question ask page). <div class="js-tag-editor tag-editor multi-line s-input">
<span>
<span class="s-tag rendered-element">java<button class="s-tag--dismiss baw0 js-delete-tag" type="button" title="Remove tag"><svg …></svg></button></span>
</span>
<input type="text" id="tageditor-replacing-tagnames--input" class="s-input js-tageditor-replacing" …>
</div>We could consider making this more specific and only applying the focus styles to |
I would say to keep the |
|
@giamir I've removed the |
giamir
left a comment
There was a problem hiding this comment.
Thanks @dancormier for improving the docs with this use case. Apart from a small copy/paste error everything looks good to me.
I also noticed that the example doesn't look right in dark mode (see screenshot). I believe we could apply some atomic classes to make sure the page stays in harmony.
Thank you. 🙂
giamir
left a comment
There was a problem hiding this comment.
Looks good to go now. Thanks for addressing the comments. 🙂

In the process of reviewing https://github.com/StackEng/StackOverflow/pull/18700, we identified an issue with non-focusable elements styled to look like inputs with
.s-input(tag editor input for example). These elements contain invisible or restyled input elements. We want to ensure that the elements with.s-input(or similar) receive focus styling when child elements are focused.Related: #1629