uploadcare-widget icon indicating copy to clipboard operation
uploadcare-widget copied to clipboard

add support for removing styles and stylesheet urls to CssCollector

Open rnwelsh opened this issue 2 years ago • 2 comments

Description

Styling with uploadcare.tabsCss.addUrl() and uploadcare.tabsCss.addStyle() would benefit from the ability to also have methods for removeUrl() and removeStyle(). This pr adds those capabilities. The issue I came across without remove methods may never be seen in a production release, but when testing how custom iframe styling looks with a light theme and dark theme, I realized that stylesheet urls can't be toggled, so it gets stuck. Also, there is nothing keeping the same style tag added to the iframe repeatedly, so in testing I am seeing a new style added every time I toggle the theme. Again, probably only something that would be noticed in production, but easy enough to fix.

n/a

  • add removeStyle() and removeUrl() methods to CssCollector. (using array.filter())
  • utilize array.includes() instead of array.indexOf() for checking membership
    • array.includes is supported in all modern environments and is more descriptive of what is actually being checked for
    • I realize that array.indexOf(item) >= 0 is used in many other places, but that's not why I'm making this PR. I just figured I would include this small update to this action only.
  • add array.indexOf() check to addStyle() to prevent the same style tag from being duplicated

Checklist

rnwelsh avatar Mar 18 '22 22:03 rnwelsh

This pull request introduces 1 alert when merging d95c1103f6834220279ad32af90f6140a92be5b7 into 98807d197a2ad81c70c7f3b4719dfd9f0a0106a9 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

lgtm-com[bot] avatar Mar 18 '22 22:03 lgtm-com[bot]

Hey @rnwelsh, thanks for the contributing!

Unfortunately, using Array.includes can break backward compatibility for some of our customers whose users use IE10+, which support we claim. Therefore, it's still better to use an old school Array.indexOf.

nd0ut avatar Apr 04 '22 11:04 nd0ut