-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close modals when clicking outside of them #3578
Close modals when clicking outside of them #3578
Conversation
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.
Looks Good!
Hi @schlessera,
Wow, this has such great and thorough tests.
And closing the search modal in Twenty Twenty worked as expected:
'on' => 'event:action;other-event:other-action', | ||
'some-attribute' => 'value-a', | ||
], | ||
], |
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.
Nice, very thorough testing.
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.
Tests cover all the possible scenarios I can think of, and are thorough.
* @param DOMElement $to DOM element to copy the attributes to. | ||
* @param string $default_separator Default separator to use for multiple values if the attribute is not known. | ||
*/ | ||
public static function copy_attributes( $attributes, DOMElement $from, DOMElement $to, $default_separator = ',' ) { |
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.
Good idea to create this function.
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.
Excellent work overall; it works exactly as described 👌.
'on' => 'event:action;other-event:other-action', | ||
'some-attribute' => 'value-a', | ||
], | ||
], |
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.
Tests cover all the possible scenarios I can think of, and are thorough.
Summary
This PR adds a set of AMP actions to the
<amp-lightbox>
element that is used to replace the TwentyTwenty modals. Basically, the<amp-lightbox>
is yet another "toggle" to close the modal.As there's another
.modal-inner
element that contains all the actionable elements of the modal including its container, the<amp-lightbox>
is effectively the background in the AMP context.This PR offered a few technical challenges that made the solution non-trivial and required adding two helper methods:
AMP_DOM_Utils::copy_attributes()
is used to copy a set of attributes from one element to the other. This helper method makes it easier in our case to move all the relevant bits from the original modal element to the<amp-lightbox>
replacements. This was previously just a class attribute, but is now the following attributes instead:'class'
,'on'
(for moving the actions over),'data-toggle-target'
(which is needed for the generic toggle functionality to know what to target).AMP_DOM_Utils::merge_amp_actions()
is added (and used as part ofAMP_DOM_Utils::add_amp_action()
) to allow for smart deduplication of AMP actions. This is now needed as the<amp-lightbox>
is turned into a toggle as well, while already being a modal. As the toggle functionality addstoggleClass()
actions for the'active'
class on both toggles and their modals, we ended up with a duplicate toggle on the modal, which cancel each other out. The deduplication inmerge_amp_actions()
makes sure this doesn't happen.Both helper methods are generic tools that prove to be useful and come with tests, so they were added to
AMP_DOM_Utils
, and not as internal helpers for theAMP_Core_Theme_Sanitizer
.Fixes #3570
Checklist