Skip to content

Commit

Permalink
Merge pull request #24 from happyprime/fix/add-persistent-has-been-to…
Browse files Browse the repository at this point in the history
…ggled

Add persisting `toggle-block-has-been-toggled` class to toggled element when first toggled
  • Loading branch information
jeremyfelt authored Oct 10, 2024
2 parents 7c6cba0 + 54cb2ec commit debbf15
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ When the toggle block is selected in the editor, toggle settings appear in the s
The "Controls ID" entered in this panel must match the "HTML anchor" assigned to another block through its advanced panel:

<img src="assets/screenshot-toggle-block-002.png" alt="A screenshot of the sidebar panel in the block editor with a text input for HTML anchor" style="width:250px; height:auto;">

## Changelog

### 0.3.1

* Add persisting `toggle-block-has-been-toggled` class to toggled element when first toggled.

### 0.3.0

* Add persisting `toggle-block-has-toggled` class to toggle button when first clicked.
* Update `@wordpress/scripts` to 27.7.0.
* Update project dependencies.
2 changes: 1 addition & 1 deletion build/view.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array(), 'version' => '6b7ecb7568166b83bfb7');
<?php return array('dependencies' => array(), 'version' => 'ce526b75a97af67a6dd1');
2 changes: 1 addition & 1 deletion build/view.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "happyprime/toggle-block",
"description": "Add a toggle to show and hide another block.",
"version": "0.3.0",
"version": "0.3.1",
"type": "wordpress-plugin",
"minimum-stability": "stable",
"license": "GPLv2-or-later",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toggle-block",
"version": "0.3.0",
"version": "0.3.1",
"description": "Add a toggle to show and hide another block",
"author": "Happy Prime",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Plugin Name: Toggle Block
* Description: Add a toggle to show and hide another block.
* Version: 0.3.0
* Version: 0.3.1
* Plugin URI: https://github.com/happyprime/toggle-block/
* Author: Happy Prime
* Author URI: https://happyprime.co
Expand Down
9 changes: 9 additions & 0 deletions src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
evt.target.classList.add( 'toggle-block-has-toggled' );
}

/**
* Add a persisting class to the toggled block when it is
* toggled for the first time to flag that it has, at one
* point in its history, been toggled.
*/
if ( ! toggledBlock.classList.contains( 'toggle-block-has-been-toggled' ) ) {
toggledBlock.classList.add( 'toggle-block-has-been-toggled' );
}

if ( toggledBlock.classList.contains( 'toggle-block-hidden' ) ) {
evt.target.setAttribute( 'aria-pressed', 'true' );
evt.target.setAttribute( 'aria-expanded', 'true' );
Expand Down

0 comments on commit debbf15

Please sign in to comment.