Media: Add a checkbox to toggle infinite scrolling in the media modal - #12795
Media: Add a checkbox to toggle infinite scrolling in the media modal#12795itzmekhokan wants to merge 3 commits into
Conversation
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.
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
… and media items.
joedolson
left a comment
There was a problem hiding this comment.
This works well within a limited scope, but I think it needs to save the user's preference, rather than just persisting for the duration of the modal. Along with that, notices that inform the user of the preference toggle would be needed.
I pushed a minor visual improvement to fix alignments.
| } ), | ||
| label = $( '<label />', { | ||
| 'for': id, | ||
| text: __( 'Enable infinite scrolling' ) |
There was a problem hiding this comment.
I think that this label should just be "Infinite scrolling"; the checked status conveys whether it's enabled or not.
| this.infiniteScrolling = infiniteScrolling; | ||
| this.attachments.options.infiniteScrolling = infiniteScrolling; | ||
| this.$el.toggleClass( 'has-load-more', ! infiniteScrolling ); | ||
|
|
There was a problem hiding this comment.
I think it may be helpful to include some kind of visual affordance that confirms that something has happened, since all the control changes happen out of the viewport.
I also think that the control needs to save this preference for the user, so one possibility would be a notice that appears/is spoken saying "Infinite scrolling preference saved"
…owser. The checkbox that turns infinite scrolling on and off now writes the same "Infinite Scrolling" personal option as the profile screen, through a new `save-media-infinite-scrolling` AJAX action, so the choice persists beyond the current view. Changing the checkbox displays a confirmation next to it and sends the same message to `wp.a11y.speak()`, since the "Load more" button it reveals is at the end of the list of attachments and is usually out of view. Because the control saves that personal option, it is only rendered when saving the option takes effect. `wp_enqueue_media()` now reports whether a `media_library_infinite_scrolling` filter callback overrides the option, or there is no user to save it for. The label is shortened to "Infinite scrolling", as the checked state conveys whether it is enabled. See #65775.
|
Thanks for the review — all three points are addressed in c763743.
One decision worth your input. Since the control saves the personal option, |
Adds a point-of-use control for infinite scrolling in the attachments browser, as a follow-up to #65564.
What the problem was:
What the fix does:
save-media-infinite-scrollingAJAX action writes the sameinfinite_scrollingpersonal option as the profile screen, and the two stay in sync in both directions.wp.a11y.speak(), because the controls that change are at the end of the list and usually out of view.Approach and why:
wp_enqueue_media()passes a newcanToggleInfiniteScrollingsetting, which is false when amedia_library_infinite_scrollingfilter callback overrides the option, or when there is no user to save it for. Announcing "Preference saved" for a value a filter overrides on the next page load would be misleading, so no control is offered in that case. This is deliberately blunt: any callback on the filter hides the control, even one that only applies conditionally.media_library_infinite_scrollingfilter and the profile option still determine the initial state, and their documented precedence is unchanged.infiniteScrollingmoves from a module-level constant to per-instance state onAttachmentsBrowser, and is passed down to theAttachmentsview rather than read from the global a second time..attachments-wrapperis 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.