adobe / spectrum-web-components

Spectrum Web Components
https://opensource.adobe.com/spectrum-web-components/
Apache License 2.0
1.21k stars 192 forks source link

[Feat]: Truncated should reflect dynamic text updates #4503

Open spdev3000 opened 1 month ago

spdev3000 commented 1 month ago

Code of conduct

Impacted component(s)

Truncated

Description of the requested feature

When the text in sp-truncated gets changed dynamically the component should reflect that changes and update the text in the tooltip.

Mockups or screenshots

Current behavior, see: https://studio.webcomponents.dev/edit/bvy2ZIJMtqH0wE2L1kO4/src/index.ts?p=stories

Implementation notes or ideas

I used MutationController from @lit-labs/observers/mutation-controller.js to reflect textContent only changes from default slot with

new MutationController(this, {
      config: {
        characterData: true,
        childList: true,
        subtree: true,
      },
      callback: () => {
        this.copyText()
      },
    })