spectrum-web-components icon indicating copy to clipboard operation
spectrum-web-components copied to clipboard

[Feat]: sp-tag option to delete without removing from DOM

Open adixon-adobe opened this issue 11 months ago • 3 comments

Code of conduct

  • [X] I agree to follow this project's code of conduct.

Impacted component(s)

sp-tag

Description of the requested feature

We've seen some issues with the behavior of sp-tag on delete, and our framework which re-uses DOM elements -- we can get into a state where the framework is supposed to render an sp-tag, but it doesn't because it's been removed. While it's easy to add a preventDefault to the delete event, it's also an easy gotcha for new developers. The simplest improvement here would be to add an example to the docs where the deletion is handled automatically.

I'm writing this up as a feature request though so there can at least be some discussion of the philosophy here. I know in our application we want the button to be available, but we'd prefer to manage the DOM state ourselves. Maybe a self-managed attribute should be added similar to sp-tooltip?

Mockups or screenshots

No response

Implementation notes or ideas

No response

adixon-adobe avatar Feb 29 '24 16:02 adixon-adobe

event.preventDefault() is the browsers API for preventing things and the main path to "controlling" an element. I'm not sure what sort of alternate API you'd want to see here that didn't diverge from the architecture established by the platform itself.

Westbrook avatar Mar 05 '24 00:03 Westbrook

The one reason this continues to give me pause is that the default behavior can create subtle bugs, and that there aren't common html patterns where a DOM element removes itself.

adixon-adobe avatar Mar 07 '24 21:03 adixon-adobe

I would also guess that in most use cases for this, clients need to actually persist the change somehow, and update an internal list of tags (at which point the element removing itself from the DOM is likely redundant).

adixon-adobe avatar Mar 07 '24 22:03 adixon-adobe