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

Commit a1ff59d

Browse files
authored
Filter by Attribute: Allow reselecting unselected attribute (#1264)
* Filter by Attribute: Allow reselecting unselected attribute * Run prettier
1 parent ecede2c commit a1ff59d

File tree

1 file changed

+22
-19
lines changed
  • assets/js/blocks/attribute-filter

1 file changed

+22
-19
lines changed

assets/js/blocks/attribute-filter/edit.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,31 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak } ) => {
216216
);
217217
}, [] );
218218

219-
const onChange = useCallback( ( selected ) => {
220-
const selectedId = selected[ 0 ].id;
221-
const productAttribute = find( ATTRIBUTES, [
222-
'attribute_id',
223-
selectedId.toString(),
224-
] );
219+
const onChange = useCallback(
220+
( selected ) => {
221+
const selectedId = selected[ 0 ].id;
222+
const productAttribute = find( ATTRIBUTES, [
223+
'attribute_id',
224+
selectedId.toString(),
225+
] );
225226

226-
if ( ! productAttribute || attributeId === selectedId ) {
227-
return;
228-
}
227+
if ( ! productAttribute || attributeId === selectedId ) {
228+
return;
229+
}
229230

230-
const attributeName = productAttribute.attribute_name;
231+
const attributeName = productAttribute.attribute_name;
231232

232-
setAttributes( {
233-
attributeId: selectedId,
234-
heading: sprintf(
235-
// Translators: %s attribute name.
236-
__( 'Filter by %s', 'woo-gutenberg-products-block' ),
237-
attributeName
238-
),
239-
} );
240-
}, [] );
233+
setAttributes( {
234+
attributeId: selectedId,
235+
heading: sprintf(
236+
// Translators: %s attribute name.
237+
__( 'Filter by %s', 'woo-gutenberg-products-block' ),
238+
attributeName
239+
),
240+
} );
241+
},
242+
[ attributeId ]
243+
);
241244

242245
const renderAttributeControl = () => {
243246
const messages = {

0 commit comments

Comments
 (0)