Account for syntax errors in closest selector

Certain browsers have the closest method but do not
support not selectors with multiple arguments. This
variant caters for both.

Bug: T325113
Change-Id: Ib5fc912bfe0f831fea4c9882c25b27541d83b66f
This commit is contained in:
Jon Robson 2022-12-13 14:14:35 -08:00
parent 01e3ddcda5
commit 7295ee3a6a
3 changed files with 4 additions and 2 deletions

Binary file not shown.

Binary file not shown.

View file

@ -150,9 +150,11 @@ function legacyClosest( element, selector ) {
*/
export function findNearestEligibleTarget( element ) {
const selector = selectors.join( ', ' );
if ( element.closest ) {
try {
return element.closest( selector );
} else {
} catch ( e ) {
// The browser either doesn't support the selector we gave it or doesn't
// have the closest method.
return legacyClosest( element, selector );
}
}