Skip to content

Commit

Permalink
GH-780 Fix selected colour string
Browse files Browse the repository at this point in the history
When a value is clicked, the name of the selected colour is displayed.
This does now contain the translated string.
Also added the colour name as aria label.
  • Loading branch information
davidszkiba committed Dec 13, 2024
1 parent fd7504b commit c0c7a48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions amd/src/colourpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

import Templates from 'core/templates';
import {get_string as getString} from 'core/str';

const SELECTORS = {
SELECTCOLOURPICKER: 'select[name^="wb_colourpicker_"]',
Expand Down Expand Up @@ -51,19 +52,25 @@ export const init = () => {
*
* @param {mixed} selectcolor
*/
function addClickListener(selectcolor) {
const colours = [...selectcolor.querySelectorAll('option')].map(el => {
async function addClickListener(selectcolor) {
const colours = await Promise.all([...selectcolor.querySelectorAll('option')].map(async el => {

const colour = el.value;
let colourname = el.textContent;
try {
colourname = await getString('color_' + el.value + '_name', 'local_catquiz');
} catch (err) {
// Nothing to do: we already have a default value.
}

return {
colour,
colourname: el.textContent,
colourname,
colourvalue: el.innerHTML,
selected: selectcolor.value == el.value,
id: selectcolor.name
};
});
}));

const colourobject = colours.filter(e => e.selected).pop();

Expand All @@ -83,7 +90,7 @@ function addClickListener(selectcolor) {

colours.forEach(el => {
el.addEventListener('click', e => {
colourselectnotify.innerHTML = e.target.dataset.colour;
colourselectnotify.innerHTML = e.target.dataset.colourname;

colours.forEach(el => el.classList.remove('selected'));
e.target.classList.add('selected');
Expand Down
2 changes: 1 addition & 1 deletion templates/colour_pick_circle.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
}}
<span class="colourpickercircle{{#selected}} selected{{/selected}}"
style="background: {{colourvalue}};"
title="{{colour}}" data-colour="{{colour}}" data-id="colourpickercircle_id_{{id}}"></span>
title="{{colourname}}" data-colourname="{{colourname}}" aria-label="{{colourname}}" data-colour="{{colour}}" data-id="colourpickercircle_id_{{id}}"></span>

0 comments on commit c0c7a48

Please sign in to comment.