Skip to content

Commit

Permalink
Image Block: Get lightbox trigger button ref via data-wp-init (#57089)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano authored Dec 18, 2023
1 parent db617ee commit d7eeb32
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class="lightbox-trigger"
type="button"
aria-haspopup="dialog"
aria-label="' . esc_attr( $aria_label ) . '"
data-wp-init="callbacks.initTriggerButton"
data-wp-on--click="actions.showLightbox"
data-wp-style--right="context.imageButtonRight"
data-wp-style--top="context.imageButtonTop"
Expand Down
7 changes: 5 additions & 2 deletions packages/block-library/src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,16 @@ const { state, actions, callbacks } = store( 'core/image', {
const ctx = getContext();
const { ref } = getElement();
ctx.imageRef = ref;
ctx.lightboxTriggerRef =
ref.parentElement.querySelector( '.lightbox-trigger' );
if ( ref.complete ) {
ctx.imageLoaded = true;
ctx.imageCurrentSrc = ref.currentSrc;
}
},
initTriggerButton() {
const ctx = getContext();
const { ref } = getElement();
ctx.lightboxTriggerRef = ref;
},
initLightbox() {
const ctx = getContext();
const { ref } = getElement();
Expand Down

1 comment on commit d7eeb32

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in d7eeb32.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7248057706
📝 Reported issues:

Please sign in to comment.