This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 220
Mini Cart: stop using Modal component #9345
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8e6ead2
Remove unused styles
Aljullu f177530
Replace usage of Modal component with custom Drawer
Aljullu 11c0a1b
Update MiniCart.php class structure
Aljullu 79fae95
Update tests
Aljullu e845903
Prevent focus styles to appear unnecessarily when opening the Mini Ca…
Aljullu 4360f77
Work-around issue with disabled buttons causing lose of focus inside …
Aljullu 2274917
Revert "Work-around issue with disabled buttons causing lose of focus…
Aljullu 4d75aa3
QuantitySelector: focus text input field after decrease or increase b…
Aljullu 137770b
Move focus to the input field also when the body has focus, that fixe…
Aljullu 7f59f05
Add explanatory comment
Aljullu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copied from https://github.com/WordPress/gutenberg/blob/trunk/packages/components/src/modal/aria-helper.ts | ||
*/ | ||
const LIVE_REGION_ARIA_ROLES = new Set( [ | ||
'alert', | ||
'status', | ||
'log', | ||
'marquee', | ||
'timer', | ||
] ); | ||
|
||
let hiddenElements: Element[] = [], | ||
isHidden = false; | ||
|
||
/** | ||
* Determines if the passed element should not be hidden from screen readers. | ||
* | ||
* @param {HTMLElement} element The element that should be checked. | ||
* | ||
* @return {boolean} Whether the element should not be hidden from screen-readers. | ||
*/ | ||
export function elementShouldBeHidden( element: Element ) { | ||
const role = element.getAttribute( 'role' ); | ||
return ! ( | ||
element.tagName === 'SCRIPT' || | ||
element.hasAttribute( 'aria-hidden' ) || | ||
element.hasAttribute( 'aria-live' ) || | ||
( role && LIVE_REGION_ARIA_ROLES.has( role ) ) | ||
); | ||
} | ||
|
||
/** | ||
* Hides all elements in the body element from screen-readers except | ||
* the provided element and elements that should not be hidden from | ||
* screen-readers. | ||
* | ||
* The reason we do this is because `aria-modal="true"` currently is bugged | ||
* in Safari, and support is spotty in other browsers overall. In the future | ||
* we should consider removing these helper functions in favor of | ||
* `aria-modal="true"`. | ||
* | ||
* @param {HTMLDivElement} unhiddenElement The element that should not be hidden. | ||
*/ | ||
export function hideApp( unhiddenElement?: HTMLDivElement ) { | ||
if ( isHidden ) { | ||
return; | ||
} | ||
const elements = Array.from( document.body.children ); | ||
elements.forEach( ( element ) => { | ||
if ( element === unhiddenElement ) { | ||
return; | ||
} | ||
if ( elementShouldBeHidden( element ) ) { | ||
element.setAttribute( 'aria-hidden', 'true' ); | ||
hiddenElements.push( element ); | ||
} | ||
} ); | ||
isHidden = true; | ||
} | ||
|
||
/** | ||
* Makes all elements in the body that have been hidden by `hideApp` | ||
* visible again to screen-readers. | ||
*/ | ||
export function showApp() { | ||
if ( ! isHidden ) { | ||
return; | ||
} | ||
hiddenElements.forEach( ( element ) => { | ||
element.removeAttribute( 'aria-hidden' ); | ||
} ); | ||
hiddenElements = []; | ||
isHidden = false; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been moved from here:
woocommerce-blocks/assets/js/blocks/mini-cart/style.scss
Lines 228 to 238 in f1714a7