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

Align icon and text in a menu item #6671

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

kniziol
Copy link
Contributor

@kniziol kniziol commented Dec 29, 2024

Menu configuration

It's not necessary. It's just added to have more menu items than a single, default menu item.

// src/Controller/Admin/DashboardController.php:47

public function configureMenuItems(): iterable
{
    yield MenuItem::linkToDashboard('dashboard', 'fa fa-home');
    yield MenuItem::subMenu('Test', 'fas fa-list')
        ->setSubItems([
            MenuItem::linkToDashboard('dashboard', 'fa fa-home'),
            MenuItem::linkToDashboard('dashboard', 'fa fa-home'),
        ])
    ;
    // yield MenuItem::linkToCrud('The Label', 'fas fa-list', EntityClass::class);
}

Before (the problem)

The icon in the menu item is currently aligned to the top. It would be so much more visually appealing if both the icon and text were centered together. Just take a look at the example below (in the After section).

Icon and text alignment - before

After (the solution)

Icon and text alignment - after

@javiereguiluz
Copy link
Collaborator

@kniziol thanks for this ... but we need some changes. Sadly, it's not uncommon to have menu items that span more than 1 line. In those cases, showing the icon centered looks very ugly.

I'd say we should keep the flex-start alignment, but tweak some margin to make it look centered in the 1-line menu item case, which is the most common. Thanks.

@kniziol kniziol changed the title Center horizontally icon and text in a menu item Align icon and text in a menu item Dec 30, 2024
@kniziol
Copy link
Contributor Author

kniziol commented Dec 30, 2024

@javiereguiluz Got it. I added a margin-top to the icon so it lines up perfectly with the menu text. Take a look at the result 👇

Multiline - mobile Multiline - desktop Single line
Icon and text alignment - mobile Icon and text alignment - desktop Icon and text alignment - single line

I used the following code to generate a menu when testing:

// src/Controller/Admin/DashboardController.php

public function configureMenuItems(): iterable
{
    yield MenuItem::linkToDashboard('Ex excepteur commodo eu aliquip', 'fa fa-home');
    yield MenuItem::subMenu('Magna occaecat reprehenderit officia minim voluptate', 'fas fa-list')
        ->setSubItems([
            MenuItem::linkToDashboard('Consequat sunt esse ad incididunt commodo', 'fa fa-home'),
            MenuItem::linkToDashboard('Cillum laborum laborum sunt est Lorem', 'fa fa-home'),
        ])
    ;
    // yield MenuItem::linkToCrud('The Label', 'fas fa-list', EntityClass::class);
}

@pfpro
Copy link
Contributor

pfpro commented Dec 30, 2024

Hooray for symfony - featuring the marvelous easyadmin - and all the developers out there -
2025 up and coming - chin chin dev-ops 🎉

@javiereguiluz javiereguiluz force-pushed the bugfix/align-icon-in-menu-item branch from 22b0e74 to 3be8a66 Compare December 31, 2024 12:15
@javiereguiluz
Copy link
Collaborator

Krzysztof, thanks a lot for fixing this bug and for your extra effort during the review.

@javiereguiluz javiereguiluz merged commit 4eb8174 into EasyCorp:4.x Dec 31, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants