Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Fix error when closing product gallery dialog with keyboard escape key
Browse files Browse the repository at this point in the history
  • Loading branch information
roykho committed Nov 17, 2023
1 parent b67b264 commit f665a38
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions assets/js/blocks/product-gallery/frontend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getContext = ( ns?: string ) =>
getContextFn< ProductGalleryContext >( ns );

type Store = typeof productGallery & StorePart< ProductGallery >;
const { state, actions } = store< Store >( 'woocommerce/product-gallery' );
const { state } = store< Store >( 'woocommerce/product-gallery' );

const selectImage = (
context: ProductGalleryContext,
Expand All @@ -36,6 +36,12 @@ const selectImage = (
context.selectedImage = imagesIds[ nextImageIndex ];
};

const closeDialog = ( context: ProductGalleryContext ) => {
context.isDialogOpen = false;
// Reset the main image.
context.selectedImage = context.firstMainImageId;
};

const productGallery = {
state: {
get isSelected() {
Expand All @@ -49,9 +55,7 @@ const productGallery = {
actions: {
closeDialog: () => {
const context = getContext();
context.isDialogOpen = false;
// Reset the main image.
context.selectedImage = context.firstMainImageId;
closeDialog( context );
},
openDialog: () => {
const context = getContext();
Expand Down Expand Up @@ -127,7 +131,7 @@ const productGallery = {

// Check if the esc key is pressed.
if ( event.code === 'Escape' ) {
actions.closeDialog();
closeDialog( context );
}

// Check if left arrow key is pressed.
Expand Down

0 comments on commit f665a38

Please sign in to comment.