Skip to content

Add function to grab text content from any slot #201

@jordanjones243

Description

@jordanjones243

Support Request Description

Add function to grab text content from any slot. This will be used across all repos when needing to populate attributes/properties with slot content.

Possible Solution

  getSlotText(elem, name) {
    const slot = elem.shadowRoot?.querySelector(`slot[name="${name}"]`);
    const nodes = slot?.assignedNodes({ flatten: true }) || [];
    const text = nodes.map(n => n.textContent?.trim()).join('').trim();
    return text || null;
  }

Additional context

Needed to complete this story:
https://itsals.visualstudio.com/E_Retain_Content/_boards/board/t/Auro%20Design%20System/Stories?System.IterationPath=%40currentIteration%2CE_Retain_Content&System.AssignedTo=Jordan.Jones4%40alaskaair.com&workitem=1352598

Exit criteria (To be determined by the Auro team)

No response

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions