Skip to content

Conversation

yogeshbhutkar
Copy link
Contributor

What?

Follow-up to #70227 (comment)

This PR implements an internal editing state for SingleTrackEditor and uses the onChange to write the state to attributes only when Apply is pressed.

Why?

Previously, for every change in value, the onChange would execute, writing the state changes to attributes as they occurred; this rendered the Apply button useless.

Removing the Apply button itself was previously discussed in the tagged PR, but it was decided to keep it for better Accessibility and UX.

How?

An internal state is maintained, and the state is synced with attributes when the changes are applied; otherwise, they are discarded.

Testing Instructions

  1. Create a Video block.
  2. Attach a Track to it by selecting a subtitle file from the Media Library.
  3. Fill in the details. Do not click Apply and then close the modal.
  4. Reopen the single-track editing modal, and confirm that the states are reverted.

Testing Instructions for Keyboard

Same.

Screencast

pr-demo.mov

* Also contains logic to simplify writing defaults
const DEFAULT_TRACK = {
src: '',
label: '',
srcLang: 'en',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intended to omit the language-specific srcLang attribute from the previous implementation; however, according to the MDN reference:

If the kind attribute is set to "subtitles", then srclang must be specified.

Even when the kind attribute is omitted, it defaults to "subtitles", which still requires srclang to be defined.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mamaduka, can we move this PR forward if the implementation looks good? 😅

@yogeshbhutkar yogeshbhutkar marked this pull request as ready for review July 7, 2025 10:48
Copy link

github-actions bot commented Jul 7, 2025

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

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

@yogeshbhutkar yogeshbhutkar changed the title Video Track Editor: Fix single track state saves without applying Video: Fix track editor state saves without explicitly applying the changes Jul 7, 2025
@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Block] Video Affects the Video Block props-bot Adding this label triggers the Props Bot workflow for a PR. labels Jul 7, 2025
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Jul 10, 2025
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thank you, @yogeshbhutkar!

The refactoring works as expected ✅

@Mamaduka Mamaduka merged commit a758c66 into WordPress:trunk Jul 10, 2025
76 of 80 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.3 milestone Jul 10, 2025
cbravobernal pushed a commit that referenced this pull request Jul 15, 2025
…hanges (#70628)

Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Video Affects the Video Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants