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 and artemiomorales committed Jan 4, 2024
1 parent e6936e5 commit 3177b9f
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

0 comments on commit 3177b9f

Please sign in to comment.