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

Alignment issue with Switch without text #10

Open
nevf opened this issue May 27, 2019 · 7 comments
Open

Alignment issue with Switch without text #10

nevf opened this issue May 27, 2019 · 7 comments

Comments

@nevf
Copy link

nevf commented May 27, 2019

When I have a matter-switch without any <span>_text_</span> the vertical position of the switch is moved way up as shown below.

image

Using a Space for text doesn't fix this and &nbsp; displays &nbsp;

I was actually trying to put the switch inside the button when I first saw this.

I assume checkbox's etc. have the same issue.

@DevFelixDorn
Copy link

+1 checkbox, radio had the same problem

@finnhvman
Copy link
Owner

@nevf @DevFelixDorn I see, I'll look into it.

@nevf
Copy link
Author

nevf commented May 28, 2019

@finnhvman Thanks. text should be optional for all of these.

@nevf
Copy link
Author

nevf commented May 28, 2019

I've got a switch without any text inside an <a> element and see a weird focus? outline when the <a> has focus. I assume this is related to my original issue.

image

@finnhvman
Copy link
Owner

@nevf @DevFelixDorn The Matter Switch, Radio, and Checkbox components rely on the same html structure, the root cause is basically the same for all these.

As far as I understood it's related to the vertical-align property having the baseline the default value (CSS Spec). The outer-most wrapping element of these controls is the . In case there's text in the label, the baselines of the label and sibling controls are aligned well, if there's no text in the label it gets messed up.

One solution I can suggest is using a Zero-Width Space as text like <span>&#8203;</span>.

The other solution could be me adding vertical-align: middle; to the of these controls, but that would mess up the nice baseline alignment in case of texts.

What are your use cases for these controls without text?


@nevf The weird focus issue is probably the browser figuring out a combined outline of all the children elements of the anchor. In case of the Switch it's the pseudo element used for the ripple that causes the irregularity. You know, the growing and fading blue circle when you switch the switch. I can't really get around this issue, because of the CSS-onliness.

Although, I have to ask, why are you putting a Switch inside of an anchor?

According to HTML Specification it's not permitted (and it's not good UX):

Permitted content | Transparent, containing either flow content (excluding interactive content) or phrasing content.

@DevFelixDorn
Copy link

DevFelixDorn commented May 29, 2019

I need only a switch without span when I had a more complex layout which require some complex flexbox/grid. It's happened not really often but it's happened ¯_(ツ)_/¯
I don't put input in anchor elements

@nevf
Copy link
Author

nevf commented May 29, 2019

@finnhvman Ben I'm using switch and checkbox in menu and tree items where the text is not part of the switch/checkbox. Further there are areas where I just use an icon + switch/checkbox with no text.

This screen shot shows examples of both:
image
A menu item/row is an <a> with text, links, switch/checkbox inside it. I'll look at revisiting using an anchor for this type of menu item.

Would having two variations of switch/checkbox etc. be the solution, one with the text <span> and one without?

Would the latter resolve my focus issue?

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

3 participants