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

Try: add icons to media type dropdowns #8566

Draft
wants to merge 13 commits into
base: trunk
Choose a base branch
from

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Mar 21, 2025

Description

The new Customizable Select API enables HTML select elements that can include images to make select elements more helpful for users.

This PR uses this new feature to add icons next to the media type dropdown in the media library.

Screenshots

Before PR

Before this PR, the media filter looks like this:

Grid view

current media filter - grid

List view

current media filter list view

After PR

Grid view

fixed grid

List view

fixed 1

Notes

  • Uses existing core dashicons for all images.
  • Non-supporting browsers show the standard select element, ignoring the icons.
  • Still works exactly like a regular select element
  • I only added minimal styling, we probably want to have the background match other dropdowns.
  • Issue: after selecting a filter, the selected item shown at the top does not include the icon, possibly because we are manually setting this value?
    icon missing

Trac ticket: None: this is an experiment so far.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@adamsilverstein
Copy link
Member Author

@argyleink any tips on showing the icon in the selected element at the top, do I need to handle that manually? (see note in PR description & screenshots)

@argyleink
Copy link

I got you: codepen doing exactly what you want

  1. add some HTML for the selected option inside the select:
  <button>
    <selectedcontent></selectedcontent>
  </button>
  1. style that selectedcontent element how you like:
    selectedcontent {
      display: flex;
      align-items: center;
      gap: .5ch;
    }

you can also use this technique to have the selected state only show the icon

@adamsilverstein
Copy link
Member Author

I got you: codepen doing exactly what you want

Excellent, thank you! I suspected I was missing something.

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 this pull request may close these issues.

2 participants