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

Dashboard accessibility improvements #11703

Merged
merged 15 commits into from
Aug 12, 2022
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
3 changes: 2 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
- Added `craft\web\View::EVENT_AFTER_CREATE_TWIG`. ([#11774](https://github.com/craftcms/cms/pull/11774))

### Changed
- Improved the control panel accessibility. ([#11534](https://github.com/craftcms/cms/pull/11534), [#11565](https://github.com/craftcms/cms/pull/11565), [#11578](https://github.com/craftcms/cms/pull/11578), [#11589](https://github.com/craftcms/cms/pull/11589), [#11610](https://github.com/craftcms/cms/pull/11610), [#11613](https://github.com/craftcms/cms/pull/11613), [#11768](https://github.com/craftcms/cms/pull/11768))
- Improved the control panel accessibility. ([#11534](https://github.com/craftcms/cms/pull/11534), [#11565](https://github.com/craftcms/cms/pull/11565), [#11578](https://github.com/craftcms/cms/pull/11578), [#11589](https://github.com/craftcms/cms/pull/11589), [#11610](https://github.com/craftcms/cms/pull/11610), [#11613](https://github.com/craftcms/cms/pull/11613), [#11703](https://github.com/craftcms/cms/pull/11703), [#11768](https://github.com/craftcms/cms/pull/11768))
- `users/session-info` responses now include a `csrfTokenName` key. ([#11706](https://github.com/craftcms/cms/pull/11706))
- `craft\helpers\Component::iconSvg()` now namespaces the SVG contents, and adds `aria-hidden="true"`. ([#11703](https://github.com/craftcms/cms/pull/11703))
- `craft\services\Search::EVENT_BEFORE_INDEX_KEYWORDS` is now cancellable by setting `$event->isValid` to `false`. ([#11705](https://github.com/craftcms/cms/discussions/11705))
- `checkboxSelect` inputs without `showAllOption: true` now post an empty value if no options were selected. ([#11748](https://github.com/craftcms/cms/issues/11748))
37 changes: 25 additions & 12 deletions src/helpers/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Craft;
use craft\base\ComponentInterface;
use craft\errors\MissingComponentException;
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;

/**
Expand Down Expand Up @@ -144,7 +145,7 @@ public static function mergeSettings(array $config): array
}

/**
* Returns an SVG icon’s contents.
* Returns an SVG icon’s contents, namespaced and with `aria-hidden="true"` added to it.
*
* @param string|null $icon The path to the SVG icon, or the actual SVG contents
* @param string $label The label of the component
Expand All @@ -157,23 +158,35 @@ public static function iconSvg(?string $icon, string $label): string
return self::_defaultIconSvg($label);
}

if (stripos($icon, '<svg') !== false) {
return $icon;
}
if (stripos($icon, '<svg') === false) {
$icon = Craft::getAlias($icon);

$icon = Craft::getAlias($icon);
if (!is_file($icon)) {
Craft::warning("Icon file doesn't exist: $icon", __METHOD__);
return self::_defaultIconSvg($label);
}

if (!is_file($icon)) {
Craft::warning("Icon file doesn't exist: $icon", __METHOD__);
return self::_defaultIconSvg($label);
if (!FileHelper::isSvg($icon)) {
Craft::warning("Icon file is not an SVG: $icon", __METHOD__);
return self::_defaultIconSvg($label);
}

$icon = file_get_contents($icon);
}

if (!FileHelper::isSvg($icon)) {
Craft::warning("Icon file is not an SVG: $icon", __METHOD__);
return self::_defaultIconSvg($label);
// Namespace it
$ns = StringHelper::randomString(10);
$icon = Html::namespaceAttributes($icon, $ns, true);

// Add aria-hidden="true"
try {
$icon = Html::modifyTagAttributes($icon, [
'aria' => ['hidden' => 'true'],
]);
} catch (InvalidArgumentException) {
}

return file_get_contents($icon);
return $icon;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/icons/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/icons/excite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/icons/feed.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/icons/newspaper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading