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

fix: Fixes form markup in text track settings #8557

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/js/tracks/text-track-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Component from '../component';
import ModalDialog from '../modal-dialog';
import {createEl} from '../utils/dom';
import * as Obj from '../utils/obj';
import * as Guid from '../utils/guid.js';
import log from '../utils/log';

const LOCAL_STORAGE_KEY = 'vjs-text-track-settings';
Expand Down Expand Up @@ -303,6 +304,12 @@ class TextTrackSettings extends ModalDialog {
* @param {string} key
* Configuration key to use during creation.
*
* @param {string} [legendId]
* Id of associated <legend>.
*
* @param {string} [type=label]
* Type of labelling element, `label` or `legend`
*
* @return {string}
* An HTML string.
*
Expand All @@ -312,12 +319,13 @@ class TextTrackSettings extends ModalDialog {
const config = selectConfigs[key];
const id = config.id.replace('%s', this.id_);
const selectLabelledbyIds = [legendId, id].join(' ').trim();
const guid = `vjs_select_${Guid.newGUID()}`;

return [
`<${type} id="${id}" class="${type === 'label' ? 'vjs-label' : ''}">`,
`<${type} id="${id}"${type === 'label' ? ` for="${guid}" class="vjs-label"` : ''}>`,
this.localize(config.label),
`</${type}>`,
`<select aria-labelledby="${selectLabelledbyIds}">`
`<select aria-labelledby="${selectLabelledbyIds}" id="${guid}">`
].
concat(config.options.map(o => {
const optionId = id + '-' + o[1].replace(/\W+/g, '');
Expand Down
14 changes: 14 additions & 0 deletions test/unit/tracks/text-track-settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,17 @@ QUnit.test('should update on languagechange', function(assert) {

player.dispose();
});

QUnit.test('should associate <label>s with <select>s', function(assert) {
const player = TestHelpers.makePlayer({
tracks
});

const firstLabelFor = player.textTrackSettings.el_.querySelector('label').getAttribute('for');

assert.ok(
videojs.dom.isEl(player.textTrackSettings.el_.querySelector(`#${firstLabelFor}`)),
'label has a `for` attribute matching an `id`'
);

});