Skip to content

Media: Add a checkbox to toggle infinite scrolling in the media modal - #12795

Open
itzmekhokan wants to merge 1 commit into
WordPress:trunkfrom
itzmekhokan:fix/65775-media-modal-infinite-scroll-toggle
Open

Media: Add a checkbox to toggle infinite scrolling in the media modal#12795
itzmekhokan wants to merge 1 commit into
WordPress:trunkfrom
itzmekhokan:fix/65775-media-modal-infinite-scroll-toggle

Conversation

@itzmekhokan

Copy link
Copy Markdown

Adds a point-of-use control for infinite scrolling in the attachments browser, as a follow-up to #65564.

What the problem was:

  • Infinite scrolling is enabled by default as of [62632], but the only way to change it is the "Infinite Scrolling" option on the user profile screen. Users who need the "Load more" button for accessibility, or who want to avoid loading a large library, have to leave the modal, change their profile, and come back.

What the fix does:

  • Renders a checkbox before the list of media items, in both the media modal and the Media Library grid view, that turns infinite scrolling on and off immediately.
  • Unchecking it reveals the "Load more" button and the item count and stops the scroll handler from requesting more attachments. Checking it hides them and resumes loading on scroll.
  • Keeps the screen reader search-results message in sync with the active mode.

Approach and why:

  • The checkbox reflects the value resolved by wp_enqueue_media() and overrides it for the current view only, so the media_library_infinite_scrolling filter and the user profile option still determine the initial state and their documented precedence is unchanged.
  • infiniteScrolling moves from a module-level constant to per-instance state on AttachmentsBrowser, and is passed down to the Attachments view rather than read from the global a second time.
  • The scroll handler is now always bound and bails when infinite scrolling is off, so it is live if the user turns scrolling on mid-session.
  • To make room for a control before the list, .attachments-wrapper is now the positioned, scrolling region in both modes rather than only when the "Load more" button is present. This reuses the offsets that already applied to the wrapper at every breakpoint, so no per-breakpoint pixel values change.

Trac ticket: https://core.trac.wordpress.org/ticket/65775

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Ticket analysis, tests and generate PR. All changes were reviewed and validated by me.


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.

Infinite scrolling of the attachments list can now be turned on and off at
the point of use, from a checkbox rendered before the list of media items in
both the media modal and the Media Library grid view.

The checkbox reflects the value resolved by `wp_enqueue_media()` and
overrides it for the current view only, so the
`media_library_infinite_scrolling` filter and the "Infinite Scrolling" user
profile option still determine the initial state. Turning the checkbox off
reveals the "Load more" button and stops the scroll handler from requesting
more attachments; turning it back on hides the button and resumes loading
on scroll.

To make room for the checkbox before the list, the attachments wrapper is
now the positioned, scrolling region in both modes, rather than only when
the "Load more" button is present.

Fixes #65775.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props khokansardar.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

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

  • 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.

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.

1 participant