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

Remove margin top on the input component if no label is provided in core_components.ex #5832

Open
NTurchi opened this issue Jun 4, 2024 · 2 comments · May be fixed by #5884
Open

Remove margin top on the input component if no label is provided in core_components.ex #5832

NTurchi opened this issue Jun 4, 2024 · 2 comments · May be fixed by #5884

Comments

@NTurchi
Copy link

NTurchi commented Jun 4, 2024

Environment

  • Elixir version (elixir -v):
Erlang/OTP 25 [erts-13.2.2.6] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1]

Elixir 1.16.1 (compiled with Erlang/OTP 25)
  • Phoenix version (mix deps): 1.7.12
  • Operating system: MacOS

Actual behavior

Hello Phoenix Team 👋
This is a minor issue with the input component from the core_components.ex file (used in phx.gen.live)
A margin top is added by default for the spacing between the label and the input.

class={[
"mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6 min-h-[6rem]",
@errors == [] && "border-zinc-300 focus:border-zinc-400",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}

However it is not removed if a label is not provided. Which causes alignment issue when combining the input component with other elements on our UI.

mt-2-top-screen

Of course this can be fixed easily by modifying the core_component in my project but I guess this can be a quick win improvement to update the core_components.ex directly in Phoenix. I can propose a PR if you think it's worth making a small update 🙏

Expected behavior

Avoid adding a margin to the input if a label is not provided to the input component.

Fix: one idea could be to put the mt-2 class behind a condition, e.g:

class={[ 
    "block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6 min-h-[6rem]", 
    @errors == [] && "border-zinc-300 focus:border-zinc-400", 
    @errors != [] && "border-rose-400 focus:border-rose-400",
    # new condition
    label != nil && "mt-2",
]} 
@NTurchi NTurchi closed this as completed Jun 4, 2024
@NTurchi NTurchi reopened this Jun 4, 2024
@NTurchi NTurchi changed the title Remove margin top on the input component if no label is provided in core_component.ex Remove margin top on the input component if no label is provided in core_components.ex Jun 4, 2024
@josevalim
Copy link
Member

Maybe we should add mb-2 to the label instead? A PR is welcome.

@NTurchi NTurchi linked a pull request Jul 28, 2024 that will close this issue
@HerrBertling
Copy link

HerrBertling commented Aug 27, 2024

Not sure whether the error should have the same margin as the label and textarea have between each other. If that‘s the case, you could make use of the gap classes that work with either flex or grid.

Here, you could slap some Tailwind classes onto the surrounding div and the spacing would „just“ happen between the different children, no matter if a specific one is present or not: <div class="flex flex-col gap-2">… 😊

EDIT: this article lays out in more detail why avoiding margin is overall better in composition of components: https://mxstbr.com/thoughts/margin

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

Successfully merging a pull request may close this issue.

3 participants