Skip to content

Commit

Permalink
Add new argument for a modifier to the highlight class
Browse files Browse the repository at this point in the history
  • Loading branch information
renatho committed Mar 18, 2024
1 parent 459a817 commit 62e0b56
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions assets/admin/tour/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ export function performStepAction( index, steps ) {
/**
* Highlights the elements with a border.
*
* @param {Array} selectors An array of selectors to highlight.
* @param {Array} selectors An array of selectors to highlight.
* @param {string} modifier A modifier to add to the highlight class.
*/
export function highlightElementsWithBorders( selectors ) {
export function highlightElementsWithBorders( selectors, modifier = '' ) {
const modifierSuffix = modifier ? '--' + modifier : '';
const className = HIGHLIGHT_CLASS + modifierSuffix;

selectors.forEach( function ( selector ) {
const element = document.querySelector( selector );
if ( element ) {
element.classList.add( HIGHLIGHT_CLASS );
element.classList.add( className );
}
} );
}
Expand Down
12 changes: 12 additions & 0 deletions assets/admin/tour/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ describe( 'highlightElementsWithBorders', () => {
expect( document.querySelector( selector ) ).toBeNull();
} );
} );

it( 'should add highlight class to the element with a modifier', () => {
const element = document.createElement( 'div' );

mockQuerySelector.mockImplementation( () => {
return element;
} );

highlightElementsWithBorders( [ 'div' ], 'modifier' );

expect( element.className ).toBe( HIGHLIGHT_CLASS + '--modifier' );
} );
} );

describe( 'removeHighlightClasses', () => {
Expand Down

0 comments on commit 62e0b56

Please sign in to comment.