ui-kit icon indicating copy to clipboard operation
ui-kit copied to clipboard

Selector passed into document.querySelector must be escaped

Open dogayuksel opened this issue 2 years ago • 0 comments

Describe the bug

Below, selector string is created using the id of the element.

https://github.com/commercetools/ui-kit/blob/5ce0b2aaffe76e0d9466b068c8ddc636be5ae0e2/packages/components/inputs/money-input/src/money-input.tsx#L43-L44

According to https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

Note: Characters that are not part of standard CSS syntax must be escaped using a backslash character.


To Reproduce

When the high precision price tooltip is activated on a list of MoneyInputs managed by formik, such an exception is thrown:

Screenshot 2023-06-28 at 18 57 43

Expected behavior

Non supported characters in the selector string should be escaped like so (notice double \):

document.querySelector("#portal-tiers\\.1\\.value")

Using CSS.escape(str) seems to be a good solution: https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape_static

dogayuksel avatar Jun 28 '23 17:06 dogayuksel