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

Make ToggleButtons can display only icons #15530

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

thaqebon
Copy link
Contributor

@thaqebon thaqebon commented Feb 6, 2025

Description

Add onlyIcons() to ToggleButtons to hide option labels and display only icons:

  • Hides button labels by setting them as sr-only.
  • Optionally consider option labels as icons when using options() to skip the use of icons().
use Filament\Forms\Components\ToggleButtons;

ToggleButtons::make('status')
    ->options([
        'draft' => 'Draft',
        'scheduled' => 'Scheduled',
        'published' => 'Published'
    ])
    ->icons([
        'draft' => 'heroicon-o-pencil',
        'scheduled' => 'heroicon-o-clock',
        'published' => 'heroicon-o-check-circle',
    ])
    ->onlyIcons()

Or

ToggleButtons::make('status')
    ->options([
        'draft' => 'heroicon-o-pencil',
        'scheduled' => 'heroicon-o-clock',
        'published' => 'heroicon-o-check-circle',
    ])
    ->onlyIcons(optionLabelAsIcon: true)

Visual changes

Before: option label is an empty string
before
After: use onlyIcons()
after

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

- Hide button labels by setting them as sr-only
- Optionally consider option labels as icons when using `->options()`
@danharrin
Copy link
Member

Please completely remove the optionLabelAsIcon feature since it is not accessible

Copy link
Member

@danharrin danharrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please rename the method to hiddenLabels() and areLabelsHidden() for consistency elsewhere

@danharrin danharrin added the enhancement New feature or request label Feb 6, 2025
@danharrin danharrin added this to the v3 milestone Feb 6, 2025
@thaqebon
Copy link
Contributor Author

thaqebon commented Feb 6, 2025

It's fine to remove the optionLabelAsIcon feature. However, could you suggest different names for hiding button labels? The ToggleButtons class already uses the HasLabel trait, which includes hiddenLabel() and isLabelHidden() for hiding field labels.
field-label

@danharrin
Copy link
Member

How about hiddenButtonLabels() and areButtonLabelsHidden()?

- Remove `isOptionLabelAsIcon`
@thaqebon
Copy link
Contributor Author

thaqebon commented Feb 6, 2025

How about hiddenButtonLabels() and areButtonLabelsHidden()?

Done.

@danharrin danharrin merged commit 8c2891d into filamentphp:3.x Feb 7, 2025
@danharrin
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants