Markus Michalski FAQ

Accessibility Widget: Storefront Integration

Accessibility widget for Sylius - Twig hooks, skip link target, theming via CSS custom properties, theme compatibility

Deutsche Version

Back to overview

Accessibility Widget: Storefront Integration

Live Demo: Try this and other plugins live — no installation, no risk: demo.markus-michalski.net

Twig hooks

The plugin registers itself through these hooks, no core template is overridden:

Hook Purpose
sylius_shop.base#stylesheets Loads accessibility.css; with at least one active tool also accessibility-early.js (synchronous, before the first render) and, with the colour filter active, an inline <style> with the filter rules
sylius_shop.base#javascripts Loads accessibility.js (defer), only when at least one tool is active
sylius_shop.base.header Skip link (priority 1000, at the very front) and the jump target (priority 50)
sylius_shop.base.offcanvas The floating widget itself (priority -100), outside the page wrapper

A theme that replaces these hook slots has to render the plugin's templates itself, otherwise nothing appears.

The skip link is a link <a class="mmd-a11y-skip-link" href="#mmd-a11y-main"> with the text "Skip to main content" (DE: "Zum Hauptinhalt springen"). It sits off-screen via CSS and appears only when it receives keyboard focus.

The shop's base template has no <main> and no content ID. The plugin therefore prints its own empty, focusable <div id="mmd-a11y-main" tabindex="-1" role="region"> with an aria-label ("Main content") in the hook sylius_shop.base.header, between the navigation (priority 100) and the flash messages (priority 0), so that a validation message or "added to cart" message is not skipped after the jump. Link and target appear only when the skip link setting is switched on for the channel.

If your theme places the content elsewhere, override the plugin's template following the usual Symfony pattern at templates/bundles/MmdSyliusAccessibilityPlugin/shop/skip_target.html.twig (original: templates/shop/skip_target.html.twig in the plugin).

Theming

The effects are plain classes on <html>; colours and spacing can be overridden from your theme through CSS custom properties:

:root {
    --mmd-a11y-primary: #0b6b3a;
    --mmd-a11y-primary-dark: #08522c;
    --mmd-a11y-offset-x: 24px;
    --mmd-a11y-offset-bottom: 90px;
    --mmd-a11y-z-index: 1020;
}

More properties in the stylesheet: --mmd-a11y-bg, --mmd-a11y-text, --mmd-a11y-text-light, --mmd-a11y-border, --mmd-a11y-control-border, --mmd-a11y-focus, --mmd-a11y-hover, --mmd-a11y-size and --mmd-a11y-panel-width.

Setting Classes on <html>
Font size mmd-a11y-font-small, mmd-a11y-font-large
Contrast mmd-a11y-contrast-high, mmd-a11y-contrast-inverted
Colour filter mmd-a11y-filter-protanopia, -deuteranopia, -tritanopia
Blue light mmd-a11y-blue-light
Reduce animations mmd-a11y-reduce-motion

localStorage key: mmd-accessibility-settings. A headless storefront can reuse the same classes as a convention (see Shop API).

The colour filters deliberately sit on <html>, not on a wrapper element: a filter on a wrapper would become the containing block of every position: fixed element (sticky header, banners) and break their placement.

Behaviour in detail