question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fallback/progressive enhancement

See original GitHub issue

Components this will probably be most relevant to:

  • generic-accordion
  • generic-tabs
  • generic-disclosure

Currently, its ‘recommended’ to use a button for the ‘headers’ or ‘controls’ of an accordion/tabs component. The problem with this is progressive enhancement, or a fallback if JS is not available; in that case, there will be a button, but that button does not really do anything or ‘control’ anything, which can be confusing to a user.

It may make more sense to just simply fall back to some kind of heading or text node (whatever the user should provide) instead.

If the goal of this project is to ‘enhance’ markup with some functionality like keyboard behavior and accessibility, that might be a nice/elegant fallback.

There are a few ways to go about this, but in any case, there needs to be some sort of relation between a ‘header’ and a ‘panel’:

1: custom header/panel elements

pros: has some similarity with the detail & summary elements, will somewhat elegantly fallback cons: the generic- prefix makes it somewhat awkward

<generic-accordion>
  <generic-accordion-header>Shipping information</generic-accordion-header>
  <generic-accordion-panel>Here is some shipping information</generic-accordion-panel>
  
  <generic-accordion-header>Personal information</generic-accordion-header>
  <generic-accordion-panel>Here is some personal information</generic-accordion-panel>
</generic-accordion>

An added benefit of this pattern is that it could potentially improve the stylability (without having to rely on parts) of generic-switch by doing something like:

<label for="switch">some setting</label>
<generic-switch id="switch">
  <generic-track></generic-track>
  <generic-thumb></generic-thumb>
</generic-switch>

2: require custom attributes

cons: this doesn’t really happen anywhere else in HTML (as far as I know)

<generic-accordion> 
  <h2 x-header>Shipping information</h2>
  <div x-panel>
    Here is some shipping information
  </div>
  <h2 x-header>Personal information</h2>
  <div x-panel>
    Here is some personal information
  </div>
</generic-accordion>

3: slots

pros: will just fallback to a h2 and div const: might affect stylability/customization?

<generic-accordion> 
  <h2 slot="header">Shipping information</h2>
  <div slot="panel">
    Here is some shipping information
  </div>
  <h2 slot="header">Personal information</h2>
  <div slot="panel">
    Here is some personal information
  </div>
</generic-accordion>

4: anchors

As I understand Zach Leatherman handles this by requiring the ‘headers’ to be anchor tags that link to the panels: Progressively enhances from <a> with anchor links pointing to content panels.

I guess this would look something like:

<generic-accordion> 
  <a href="#panel-1">Shipping information</a>
  <div id="panel-1">
    Here is some shipping information
  </div>
  <a href="#panel-2">Personal information</a>
  <div id="panel-2">
    Here is some personal information
  </div>
</generic-accordion>

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
thepasslecommented, May 5, 2020

It seems to me that each component might fit best into different solutions that you proposed. Are you planning on trying to come up with a more consistent approach that would be used for all of them?

It would be nice to have some kind of strategy for every component eventually yeah. But I think it’d have to be on a component to component basis, see what the best solution is for each component, and then potentially align across the board where possible. So thanks for your input! Very valuable 🙂

My current thinking is that just using slots is probably the best way forward to both be able to support a fallback, as well as a nice developer experience.

0reactions
Malvozcommented, Jan 11, 2021

https://github.com/thepassle/generic-components/issues/10#issue-611523936:

Currently, its ‘recommended’ to use a button for the ‘headers’ or ‘controls’ of an accordion/tabs component. The problem with this is progressive enhancement, or a fallback if JS is not available; in that case, there will be a button

Due to :not(:defined) { display: none }, nothing will actually be displayed to the user in browsers that support custom elements (and subsequently the :defined pseudo class) when JS is disabled.

My approach in solving this (for the Maps for HTML Community Group’s custom element) was to include a <noscript> element and reset display: none. FWIW another approach would be to use the scripting @media feature, if browsers decided to implement it. 🤷‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Graceful degradation versus progressive enhancement - W3C
In this part of the Web Standards Curriculum we discuss the difference between two development approaches: graceful degradation and progressive enhancement.
Read more >
Flex Progressive Enhancement with Float Fallback - CodePen
About HTML Preprocessors. HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write...
Read more >
Falling Forward — Rethinking Progressive Enhancement ...
Forget what you know about Progressive Enhancement. ... Most definitions of "fallback" refer to "retreat" or "emergency" or other negative ...
Read more >
Progressive Enhancement: What It Is, And How To Use It?
Progressive Enhancement is a powerful methodology that allows Web developers to concentrate on building the best possible websites while ...
Read more >
Does not provide fallback content when JavaScript is not ...
Progressive Enhancement is a web development strategy that ensures that your site is ... How the Lighthouse fallback content audit fails.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found