Skip to content

Commit

Permalink
fix: Fixes form markup in text track settings (#8557)
Browse files Browse the repository at this point in the history
  • Loading branch information
mister-ben committed Jan 16, 2024
1 parent 7345768 commit 46c9907
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/js/tracks/text-track-settings.js
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
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`'
);

});

0 comments on commit 46c9907

Please sign in to comment.