Skip to content

Commit 3e55329

Browse files
ENH Hide PHP font icons from screen readers (#416)
1 parent d689fcf commit 3e55329

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

client/dist/js/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/components/LinkField/LinkField.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,34 @@ const LinkField = ({
407407
publishButton.classList.add(className);
408408
}
409409
});
410-
const dataTextAlternate = publishButton.getAttribute('data-text-alternate');
410+
const buttonTitle = publishButton.querySelector('.btn__title');
411+
const dataTextAlternate = publishButton.dataset.textAlternate;
411412
if (dataTextAlternate) {
412-
publishButton.innerHTML = dataTextAlternate;
413+
publishButton.dataset.textStandard = buttonTitle.textContent;
414+
buttonTitle.textContent = dataTextAlternate;
415+
}
416+
417+
// Icons in the child element can also be swapped out
418+
const iconElement = publishButton.querySelector('.btn__icon');
419+
if (!iconElement) {
420+
return;
421+
}
422+
// Find the original font-icon class name (if there was one) so we can toggle back to it
423+
let standardIcon = '';
424+
for (const classname of iconElement.classList) {
425+
if (classname.match(/^font-icon-/)) {
426+
standardIcon = classname.replace(/^font-icon-/, '');
427+
break;
428+
}
429+
}
430+
if (standardIcon) {
431+
publishButton.dataset.iconStandard = standardIcon;
432+
iconElement.classList.remove(`font-icon-${standardIcon}`);
433+
}
434+
// Add alternate icon
435+
const alternateIcon = publishButton.getAttribute('data-icon-alternate');
436+
if (alternateIcon) {
437+
iconElement.classList.add(`font-icon-${alternateIcon}`);
413438
}
414439
}
415440

@@ -525,7 +550,7 @@ const LinkField = ({
525550
const renderPicker = !loadingError && !inHistoryViewer && !saveRecordFirst && (isMulti || linkIDs.length === 0);
526551
const renderModal = !loadingError && !saveRecordFirst && Boolean(editingID);
527552
const loadingErrorText = i18n._t('LinkField.FAILED_TO_LOAD_LINKS', 'Failed to load link(s)');
528-
const saveRecordFirstText = isMulti
553+
const saveRecordFirstText = isMulti
529554
? i18n._t('LinkField.SAVE_RECORD_FIRST', 'Cannot add links until the record has been saved')
530555
: i18n._t('LinkField.SAVE_RECORD_FIRST_SINGLE', 'Cannot add link until the record has been saved');
531556
const links = renderLinks();

0 commit comments

Comments
 (0)