Giter Club home page Giter Club logo

a11y-plugin's Introduction

swup 4 is released ย ๐ŸŽ‰ย  Check out the release notes andย upgradeย guide.


swup

npm version Bundle size npm downloads Test status License


Swup

Versatile and extensible page transition library for server-rendered websites.

Features โ€ข Demos โ€ข Plugins โ€ข Themes โ€ข Documentation โ€ข Discussions

Overview

Swup adds page transitions to server-rendered websites. It manages the complete page load lifecycle and smoothly animates between the current and next page. In addition, it offers many other quality-of-life improvements like caching, smart preloading, native browser history and enhanced accessibility.

Make your site feel like a snappy single-page app โ€” without any of the complexity.

Features

  • โœ๏ธ Works out of the box with minimal markup
  • โœจ Auto-detects CSS transitions & animations for perfect timing
  • ๐Ÿ”— Updates URLs and preserves native browser history
  • ๐Ÿ“ Manages the scroll position between pages and anchor links
  • ๐Ÿš€ Uses a cache to speed up subsequent page loads
  • ๐Ÿ“ก Offers hooks to customize and extend the page load lifecycle
  • ๐Ÿ”Œ Has a powerful plugin system and many official and third-party plugins
  • ๐ŸŽจ Provides ready-to-go themes to get started quickly

Demos

Explore our interactive demos to see swup in action.

Documentation

Visit our official documentation to learn more.

Plugins

Swup is small by design. Extended features can be added via plugins:

Check out the list of official plugins and third-party integrations.

Themes

Get started quickly with one of three official themes: fade, slide, and overlay.

Examples

Take a look at the interactive demos and sites using swup for more examples.

Having trouble?

If you're having trouble implementing swup, check out the Common Issues section of the docs, look at closed issues or create a new discussion.

Want to Contribute?

We're looking for maintainers! ย  ๐Ÿ‘€

Become a sponsor on Open Collective or support development through GitHub sponsors.

This project is tested with BrowserStack.

a11y-plugin's People

Contributors

daun avatar dependabot[bot] avatar gmrchk avatar hirasso avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

a11y-plugin's Issues

Reduced motion feature overwrites existing animation state

Description of the issue

  • The check for reduced motion preference is implemented in a way to not respect the current setting
  • We're now also doing the opposite, i.e. re-enabling animations even when they're already disabled
  • Practically, this means that popstate visits are now always animated if this option is enabled

How to reproduce the issue

  • Enabled respectReducedMotion
  • Trigger a history visit
  • It's animated

[Bug]: `AnnouncementTranslations` has the wrong type signature

What did you expect? ๐Ÿง

I added the announcements option as described in the readme:

{
  announcements: {
    'en-US': {
      visit: 'Navigated to: {title}',
      url: 'New page at {url}'
    },
    'de-DE': {
      visit: 'Navigiert zu: {title}',
      url: 'Neue Seite unter {url}'
    },
    '*': {
      visit: '{title}',
      url: '{url}'
    }
  }
}

What actually happened? ๐Ÿ˜ตโ€๐Ÿ’ซ

When I do that, typescript complains since it expects the default visit and url parameters to exist at the top level of the option, like this:

{
  announcements: {
    'en-US': {
      visit: 'Navigated to: {title}',
      url: 'New page at {url}'
    },
    'de-DE': {
      visit: 'Navigiert zu: {title}',
      url: 'Neue Seite unter {url}'
    },
    visit: '{title}',
    url: '{url}'
  }
}

The implementation looks like it should work as described in the documentation. So we should probably change the type of the option from this:

/** Translations of announcements, keyed by language. */
type AnnouncementTranslations = {
	[lang: string]: Announcements;
} & {
	[key in keyof Announcements]: string;
};

To this:

/** Translations of announcements, keyed by language. */
type AnnouncementTranslations = {
	[lang: string]: Announcements;
};

Also, this looks redundant to me:

const lang = document.documentElement.lang || '*';

// @ts-expect-error: indexing is messy
const templates: Announcements = announcements[lang] || announcements['*'] || announcements;

lang has already a fallback of *, so we should be able to get away with this, shouldn't we?

const lang = document.documentElement.lang || '*';

// @ts-expect-error: indexing is messy
const templates: Announcements = announcements[lang] || announcements;

Overall it looks like this could use some cleanup. Happy to take care of it after #44 has landed, to avoid merge conflicts.

Swup and plugin versions ๐Ÿ“

  • @swup/a11y-plugin 4.5.0
  • swup 4.6.1

What browsers are you seeing the problem on? ๐Ÿงญ

No response

Relevant log output ๐Ÿค“

No response

URL to minimal reproduction ๐Ÿ”—

n/a

Checked all these? ๐Ÿ“š

Support multi-language announcements

Describe the problem

  • Currently, announcement templates are configured once
  • Navigating to a page with a different lang will not change the language of announcements

Describe the proposed solutions

Tending towards option 1, or a combination of 1 and 2.

  1. Allow keying the announcement templates by language: { en: 'Navigated to', de: 'Seite geladen' }
  2. Create a hook content:announce to modify these on the fly
  3. Read the announcement templates from the DOM: <meta name="swup-a11y-announce" content="Seite geladen">

Alternatives considered

  • Hard-reloading on language change
  • Possible, but not a great user experience by any means

How important is this feature to you?

  • Nice to have
  • Would make my life a lot easier
  • I cannot use swup without it

Declaration file not being found

Description of the issue

I just installed a11y-plugin in a fresh typescript project and got this error:

Could not find a declaration file for module '@swup/a11y-plugin'.

How to reproduce the issue

  • Start a new ts project
  • Install @swup/a11y-plugin

...seems like it's due to the missing toplevel "types" property. I thought it wasn't necessary anymore due to us providing it in the "exports" field anyways, but adding it made the error go away in VSCode.

Disable animations if user prefers reduced motion

Evaluate whether we should disable transitions for devices that request reduced motion:

  • Pro: Conceptually, it's well within this plugin's core idea
  • Con: Technically, this belongs in CSS
  • Con: Turning off animations isn't reducing but removing motion completely
  • Probably make this an optional feature turned off by default

Details

Revisiting the reduced motion media query

Example code

@media screen and
  (prefers-reduced-motion: reduce), 
  (update: slow) {
  .transition-fade {
    transition-duration: 0.001ms !important;
  }
}

Add `swup.say` method

Describe the problem

When using in-site app views that alter the URL but are being ignored by swup due to the use of resolveUrl, a11y plugin doesn't announce anything, since there is no swup visit happening.

Describe the proposed solution

It would be handy to be able to manually trigger announcements:

import SwupA11yPlugin from "@swup/a11y-plugin";
const swup = new Swup({
  plugins: [
    new SwupA11yPlugin(),
  ],
});

// sometime later:
createHistoryRecord(newUrl);
swup.say?.(`Navigated to filter ${currentFilterName}`);

How important is this feature to you?

  • Nice to have

Allow dynamic focus target

Describe the problem

  • Some visits don't need to reset focus to the main element, e.g. fragment visits like filter UIs
  • Ideally, the custom focus target could be overwritten per visit
  • The fragment plugin and users can then just set visit.focus = '#list' or similar

Describe the proposed solution

  • New key in visit object: visit.focus โ€” or maybe nested/grouped somewhere?
  • New hook content:focus that can be replaced

How important is this feature to you?

  • Nice to have
  • Would make my life a lot easier
  • I cannot use swup without it

CSS docs

Describe the problem

Intuitively, I would have thought that this CSS should hide any outline on the <main> element:

main:focus {
  outline: none;
}

But in the docs it recommends this approach:

main[tabindex="-1"] {
  outline: none;
}

In my tests, it works well with the simple :focus selector. Is there a reason for the [tabindex] form being chosen in the docs?

Feature: Move focus when handling same-page links

Describe the problem ๐Ÿง

Both swup and the scroll plugin don't explicitly move focus when a same-page anchor is clicked. Focus remains on the clicked link, which is not great for keyboard and screen reader users.

We've briefly discussed the topic on an issue about the :target pseudo-lement but I never followed up on checking our implementation.

Describe the propsed solution ๐Ÿ˜Ž

Move the focus navigation starting point to the targeted anchor. Browsers these days don't directly focus the target element but merely move the focus starting point so the next tab press will find the closest interactive element to focus. Technically, the document's active element will be body โ€“ the browser merely bookmarks a position for restarting focus navigation.

Some research or prior discussions:

There's currently no way of manually setting the focus starting point without also focussing the element itself. There's a few workarounds, though, like the one below from a whatwg discussion on the topic. Given the amount of new code required for a "clean" implementation, I'd rather have this in the accessibility plugin than the core.

function setFocusStartPoint(element) {
  const tabindex = element.getAttribute('tabindex');

  element.setAttribute('tabindex', '-1');
  element.focus();
  element.blur();

  if (tabindex) {
    element.setAttribute('tabindex', tabindex);
  } else {
    element.removeAttribute('tabindex');
  }
}

Alternatives considered ๐Ÿค”

We could get away with just calling .focus() from the core, but that tends to come with styling issues.

How important is this feature to you? ๐Ÿงญ

Would make my life a lot easier

Checked all these? ๐Ÿ“š

[Bug]: Language fallback no longer working

What did you expect? ๐Ÿง

An undefined language should result in the announcement using the provided fallback.

What actually happened? ๐Ÿ˜ตโ€๐Ÿ’ซ

No announcement is made if the language is not defined in the options. This started happening in 4.5.1, specifically after this pull request was merged. The part that seemed redundant was actually the relevant implementation of the fallback: announcements['*'].

I'll make a note to fix and test this in the test branch that's currently in progress, just flagging it here so we don't forget.

Swup and plugin versions ๐Ÿ“

  • swup: *
  • a11y plugin: 4.5.1

What browsers are you seeing the problem on? ๐Ÿงญ

No response

Relevant log output ๐Ÿค“

No response

URL to minimal reproduction ๐Ÿ”—

https://github.com/swup/a11y-plugin/pull/46/files

Checked all these? ๐Ÿ“š

Create a demo site

Describe the problem ๐Ÿง

  • Testing a11y with swup could be a easier if we had a standardized demo app

Describe the propsed solution ๐Ÿ˜Ž

  • Create a demo site that can also serve as an interactive test suite

Prior art

Checked all these? ๐Ÿ“š

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.