GithubHelp home page GithubHelp logo

mrwweb / mrw-accordion Goto Github PK

View Code? Open in Web Editor NEW
14.0 14.0 0.0 705 KB

Accessible, progressively enhanced WordPress accordion block plugin

PHP 28.82% JavaScript 48.15% SCSS 23.02%
block-editor gutenberg wordpress wordpress-plugin

mrw-accordion's People

Contributors

mrwweb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mrw-accordion's Issues

Block Transforms

It would be great to support both transforming from and to other blocks. I'd love to hear what people expect for this.

Transform From

My initial thought for this is that a Heading and Paragraph could both be transformed to become the accordion title.

A more advanced transform would involve a multi-block selection that starts with a heading being transformed into the accordion title and contents.

Transform To

I'm less certain on the best approach here. In some ways, an accordion best maps to a Group block containing both the Accordion title as a heading followed by all the contents. Alternately, I could just see the accordion "releasing" all its contents to a Heading (from the title) and all the contents into the editor body or accordion's parent container. However, I don't think WordPress really has a paradigm for this except for "Ungroup". I don't know if it's possible to match that behavior or not.

Use CSS Custom Properties to enable easier styling

Because of various progressive enhancement things I'm doing, the default plugin styles have moderately high specificity. I think the best path forward is to use some custom properties so it's easier to change the styles, especially the colors and the heading/button padding.

Under consideration: Change block icon

Especially in the block list view, the current accordion icon (downward caret) doesn't look distinctive enough and blends in with the surrounding buttons (probably because it's a default WP icon):

three accordion blocks called "Accordion" in the WordPress block editor list view. The collapsed blocks are indicated by right-facing carets while the accordions are identified by larger downward facing carets

I'm not totally sure what to change it to (suggestions welcome), but I lean toward some kind of representation of the open accordion (a simplified version of this?)

Add ability to reset font size

Right now, once a font-size for the heading is selected there's no way to remove that size and re-inherit the default size of the heading. This should be possible!

Support Expand/Collapse in Editor

It would be nice to support basic expanding and collapsing in the editor both so it matches the front end experience more closely and increases confidence that the tool works. However, it can't perfectly match the front end behavior since the heading must remain editable and doesn't contain a button.

Block Styles that would be useful?

Once #20 is dealt with, the block won't be using Block Styles, which I think may be for the best. However, I could imagine some interesting block styles might be fun in the future. If you have any specific ideas, leave a comment!

As of 13 Dec 2021, there is a single "Plain" block style that removes the background and border.

Improve no-JS mode

When JavaScript is off, hasn't executed yet, or fails to execute, the accordion icon is still visible. I should do my best to hide that icon without an excessive FOUC when it gets added in.

Site-wide settings for heading level, etc.

Sites are quite likely to want to standardize a few things:

  • Heading level / font-size
  • Color
  • Alignment?

Ideally, these defaults could be set site-wide as options. However, using a block variation with isDefault would allow developers to immediately do this.

Add Heading to Save Function

After attempts with both a full save function and dynamic blocks, I'm thinking the best approach is a hybrid one where the basic fallback markup is added to the editor but not the full on version with classes, icons etc. That way, if the block fails, transforming to blocks will save all content and the heading.

Switch to HeadingLevelDropdown component for heading levels

Component source.

Off the top of my head, it'll be something like this.

import { HeadingLevelDropdown } from '@wordpress/components';

<HeadingLevelDropdown
    // options = [ 2, 3, 4 ] Do I need this or does it inherit my defaults? Maybe I should hardcode this for everyone given H1 is impossible
    value={ val }
    onChange={value => setAttribute('headingLevel', val)}
/>

Background color class not being set in 0.4.0

Testing currently on a client site, it appears that the border color inline style is set but the background color class is missing. I don't know if this is specific to this theme or a general bug. Further investigation is warranted.

Add ability to customize block settings and defaults via theme.json

I often want to hard-code one or more of the settings this block provides. In those cases, it would be nice to allow removing the various settings from the editor interface. I think I've seen examples of this done through theme.json in settings.blocks.mrw\accordion so, for instance, I could either set a default icon that's different from the plugin default OR remove the icon setting altogether.

See also: #5 for thinking about custom expand/collapse icons

Use Interactivity API for front-end

While this won't replace all the JS on the site since I still need to make the progressive enhancement-related element changes, I want to try out using the Interactivity API and this feels like almost the absolute most basic way to get started.

Icon Options

Currently the only icon options are controlled by a block style and the icons are base64-encoded SVGs. I'd like to switch to using real SVGs and styling them with CSS controlled by block options rather than block styles.

Ideally I'd like to provide the three most common icons (really just two) along with the option for a circle or not:

  • Arrow (right when closed, down when open)
  • Caret (up when closed, down when open)
  • Plus/minus

This would potentially only require two SVGs (probably inlined) and then CSS to control the circle.

The SVGs should use currentColor so they match the text by default and then an icon color option would be significantly less valuable.

2nd option: Show icon on left or right

Save the open/close state as an attribute in editor and front-end

Really nice accordion! I've tested a load of Gutenberg accordion blocks and this is by far the best.

It would be great if the open/close state was saved as an attribute, and the attribute used on the front-end and edit screen on initial page load. So as an example, if an editor sets the accordion as closed on the edit screen, the accordion would be closed both on the edit screen and on the front-end by default.

Console Error when ID does not match accordion

On a page with elements with IDs that are not accordions, the following console error is thrown for [accordion-script.js:1:1488:

Uncaught TypeError: n is null

In the page I was testing, that seemed to break smooth scrolling.

That seems to correspond to this line:

'false' === n.getAttribute('aria-expanded') && (e.classList.toggle('is-open'), n.setAttribute('aria-expanded', 'true'), o.setAttribute('aria-hidden', 'false'))

What developer hooks would be helpful?

Potential things that might be particularly useful:

  • Set default global heading level: #7
  • Set other global defaults (color, font size) - these could be handled with a block variation!
  • Change block icon #5

Add toggle to show accordion open by default

Just for the record, I don't plan on adding "one-at-a-time" open functionality or some kind of site-wide setting for this feature. I assume that closed-by-default easily falls within the 80/20 rule as the preferred default.

Errors when theme doesn't declare font sizes

Errors:

Notice: Trying to access array offset on value of type bool in \wp-content\plugins\mrw-accordion\utils.php on line 18

Notice: Trying to access array offset on value of type bool in \wp-content\plugins\mrw-accordion\utils.php on line 9

This may only happen when switching from a theme that had them?

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.