Accordion JAVASCRIPT UI Component API

Accordion Javascript API

Class

Accordion

Accordion organizes content within collapsable items.

Selector

smart-accordion

Properties

AanimationConfigures or retrieves the current animation mode. When set to 'none', all animations are disabled, resulting in instant transitions without animated effects. Setting this property to other supported values enables different animation behaviors.
DdataSourceSpecifies the data source to be loaded and displayed within the Accordion component. This property defines the collection of items or structured data that populates each section or panel of the Accordion, enabling dynamic rendering of its contents. The data source can typically be provided as an array of objects, JSON data, or via a remote endpoint depending on configuration.
DdisabledControls whether the accordion component is enabled or disabled. When set to disabled, all interactive functionality is turned off—users cannot expand, collapse, or interact with any accordion sections. Disabled accordions appear visually inactive to indicate their non-interactive state.
EexpandedIndexesSets or retrieves the indexes of currently expanded items. By assigning an array of item indexes to this property, you can programmatically expand those specific items. The maximum number of items that can be expanded at once depends on the value specified in the expandMode property (for example, single or multiple expansion modes). When getting this property, it returns an array of the indexes of all expanded items.
EexpandModeSets or retrieves the current expand mode. The expand mode specifies how list or group items behave when expanding or collapsing—such as allowing multiple items to expand simultaneously or restricting expansion to a single item at a time.
UunlockKeyRetrieves or assigns the 'unlockKey' property, which serves as the access credential required to unlock and activate the product's full features.
LlocaleSets or retrieves the current language code (e.g., "en", "fr") for the component. This property works together with the messages property to determine which language-specific messages or translations are displayed. Use this to localize your application content based on user preference or locale.
LlocalizeFormatFunctionA callback function that allows you to customize the formatting of messages returned by the Localization Module. Use this to modify or enhance localized message output—such as applying dynamic content, adjusting text structure, or handling language-specific variations—before the messages are delivered to the client application.
MmessagesSpecifies or retrieves an object containing the localized strings used throughout the widget interface. This allows you to define custom translations for various UI elements in different languages. Used together with the locale property to enable localization and internationalization support within the widget.
RreadonlyIndicates whether the element is read-only. When set to true, the element cannot be modified or interacted with by users; its value is fixed and user input is disabled. If false, the element remains editable and interactive.
RreorderControls whether users can reorder accordion items by dragging and dropping them. When enabled, items within the accordion component can be rearranged interactively; when disabled, the order of items remains fixed.
RrightToLeftSpecifies or retrieves a value that determines whether the element is aligned to accommodate right-to-left (RTL) languages and scripts, such as Arabic or Hebrew. This property ensures the element’s layout and text direction are properly adjusted to support RTL localization.
TthemeSpecifies the theme to be applied, which controls the overall appearance and visual style of the element, including aspects such as colors, fonts, and background.
UunfocusableSpecifies whether the element is capable of receiving keyboard focus, allowing users to navigate to it using the keyboard (such as the Tab key) and interact with it through assistive technologies.

Events

CcollapseTriggered when an item has completed its collapse animation and is no longer expanded or visible. This event occurs only after the item is fully collapsed, ensuring that any associated transitions or content hiding have finished.
CcollapsingFires immediately before an item begins its collapse animation, allowing you to perform actions or prevent the collapse from occurring.
DdragEndTriggered when a user completes a drag-and-drop action to reorder items, indicating that the new order has been finalized and can be processed (e.g., saved or updated in the UI or backend).
DdragStartFires when the user initiates a drag-and-drop reorder action, signaling the start of an item being moved within a sortable list or container. This event provides an opportunity to perform setup tasks, such as highlighting the item being dragged or preparing the UI for reordering.
EexpandTriggered when an item has completed its expansion and is fully visible to the user. This event occurs after any expansion animations or transitions have finished, ensuring that the item's contents are now accessible for interaction.
EexpandingFires immediately before an item begins its expansion process, allowing you to perform actions or modify data right before the expansion occurs. This event provides an opportunity to prevent the expansion or make adjustments as needed.

Methods

CcollapseCollapses the item located at the specified index, hiding its associated content or details from view. This action typically updates the user interface to indicate that the item is no longer expanded.
EexpandExpands the item located at the specified index in the collection, making its detailed content visible or accessible to the user.
IinsertInserts a new item into the array at the specified index, shifting existing elements to the right to accommodate the new entry. If the specified index is out of range, the operation will either append the item to the end or return an error, depending on the implementation.
RremoveAtRemoves the item located at the specified index from the array, shifting subsequent items one position to the left. The array's length is reduced by one, and the removed item is no longer accessible.
UupdateReplaces the item at the given index in the collection with an updated version, incorporating the specified new property values while preserving any unchanged properties.

Properties

animation"none" | "simple" | "advanced"

Configures or retrieves the current animation mode. When set to 'none', all animations are disabled, resulting in instant transitions without animated effects. Setting this property to other supported values enables different animation behaviors.

Allowed Values

  • "none" - animation is disabled
  • "simple" - ripple animation is disabled
  • "advanced" - all animations are enabled

Default value

"advanced"

Example

Set the animation property.

 <smart-accordion animation='none'></smart-accordion>

Set the animation property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.animation = 'simple';

Get the animation property.

 const accordion = document.querySelector('smart-accordion');
 let animation = accordion.animation;

dataSource{label: string, content: any}[] | AccordionItem[]

Specifies the data source to be loaded and displayed within the Accordion component. This property defines the collection of items or structured data that populates each section or panel of the Accordion, enabling dynamic rendering of its contents. The data source can typically be provided as an array of objects, JSON data, or via a remote endpoint depending on configuration.

Example

Set the dataSource property.

 <smart-accordion data-source='[{ "label": "Item 1", "content": "content 1" }, { "label": "Item 2", "content": "content 2" }, { "label": "Item 3", "content": "content 3" }]'></smart-accordion>

Set the dataSource property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.dataSource = null;

Get the dataSource property.

 const accordion = document.querySelector('smart-accordion');
 let dataSource = accordion.dataSource;

disabledboolean

Controls whether the accordion component is enabled or disabled. When set to disabled, all interactive functionality is turned off—users cannot expand, collapse, or interact with any accordion sections. Disabled accordions appear visually inactive to indicate their non-interactive state.

Default value

false

Example

Set the disabled property.

 <smart-accordion disabled></smart-accordion>

Set the disabled property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.disabled = false;

Get the disabled property.

 const accordion = document.querySelector('smart-accordion');
 let disabled = accordion.disabled;

expandedIndexesnumber[]

Sets or retrieves the indexes of currently expanded items. By assigning an array of item indexes to this property, you can programmatically expand those specific items. The maximum number of items that can be expanded at once depends on the value specified in the expandMode property (for example, single or multiple expansion modes). When getting this property, it returns an array of the indexes of all expanded items.

Example

Set the expandedIndexes property.

 <smart-accordion expanded-indexes='[0,1]'></smart-accordion>

Set the expandedIndexes property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.expandedIndexes = [2,3];

Get the expandedIndexes property.

 const accordion = document.querySelector('smart-accordion');
 let expandedIndexes = accordion.expandedIndexes;

expandMode"single" | "singleFitHeight" | "multiple" | "toggle" | "none"

Sets or retrieves the current expand mode. The expand mode specifies how list or group items behave when expanding or collapsing—such as allowing multiple items to expand simultaneously or restricting expansion to a single item at a time.

Allowed Values

  • "single" - Allows a single item to be expanded. An item is expanded according to it's content.
  • "singleFitHeight" - Allows a single item to be expanded. An item is expanded in order to fit the remaining space available. If the content of the item overlows, scroll bars will appear inside the item.
  • "multiple" - Multiple items can be expanded. Items expand according to their content.
  • "toggle" - Allows a single item to be expanded and collapsed.
  • "none" - Disables item expanding/collapsing. The current state of the items is preserved.

Default value

"singleFitHeight"

Example

Set the expandMode property.

 <smart-accordion expand-mode='multiple'></smart-accordion>

Set the expandMode property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.expandMode = 'none';

Get the expandMode property.

 const accordion = document.querySelector('smart-accordion');
 let expandMode = accordion.expandMode;

unlockKeystring

Retrieves or assigns the 'unlockKey' property, which serves as the access credential required to unlock and activate the product's full features.

Default value

""

Example

Set the unlockKey property.

 <smart-accordion unlock-key=''></smart-accordion>

Set the unlockKey property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.unlockKey = '1111-2222-3333-4444-5555';

Get the unlockKey property.

 const accordion = document.querySelector('smart-accordion');
 let unlockKey = accordion.unlockKey;

localestring

Sets or retrieves the current language code (e.g., "en", "fr") for the component. This property works together with the messages property to determine which language-specific messages or translations are displayed. Use this to localize your application content based on user preference or locale.

Default value

"en"

Example

Set the locale property.

 <smart-accordion locale='de'></smart-accordion>

Set the locale property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.locale = 'fr';

Get the locale property.

 const accordion = document.querySelector('smart-accordion');
 let locale = accordion.locale;

localizeFormatFunctionfunction | null

A callback function that allows you to customize the formatting of messages returned by the Localization Module. Use this to modify or enhance localized message output—such as applying dynamic content, adjusting text structure, or handling language-specific variations—before the messages are delivered to the client application.

Example

Set the localizeFormatFunction property.

 <smart-accordion localize-format-function='function(defaultMessage, message, messageArguments){return '...'}'></smart-accordion>

Set the localizeFormatFunction property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.localizeFormatFunction = function(defaultMessage, message, messageArguments){return '...'};

Get the localizeFormatFunction property.

 const accordion = document.querySelector('smart-accordion');
 let localizeFormatFunction = accordion.localizeFormatFunction;

messagesobject

Specifies or retrieves an object containing the localized strings used throughout the widget interface. This allows you to define custom translations for various UI elements in different languages. Used together with the locale property to enable localization and internationalization support within the widget.

Default value




"en": {

"propertyUnknownType": "'{{name}}' property is with undefined 'type' member!",

"propertyInvalidValue": "Invalid '{{name}}' property value! Actual value: {{actualValue}}, Expected value: {{value}}!",

"propertyInvalidValueType": "Invalid '{{name}}' property value type! Actual type: {{actualType}}, Expected type: {{type}}!",

"elementNotInDOM": "Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.",

"moduleUndefined": "Module is undefined.",

"missingReference": "{{elementType}}: Missing reference to {{files}}.",

"htmlTemplateNotSuported": "{{elementType}}: Browser doesn't support HTMLTemplate elements.",

"invalidTemplate": "{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM.",

"accordionItemRequired": "{{elementType}}: '{{method}}' requires an item from type \"smart-accordion-item\".",

"indexOutOfBound": "{{elementType}}: Out of bound index/indexes in '{{method}}' method.",

"invalidSettings": "{{elementType}}: '{{method}}' method accepts a string or an object as it's second parameter.",

"noItems": "{{elementType}}: No child elements found.",

"overridingProperties": "{{elementType}}: Overriding properties {{property1}} and {{property2}} applied. The '{{property1}}' property is used by default."

}

Example

Set the messages property.

 <smart-accordion messages='{"de":{"propertyUnknownType":"Die Eigenschaft '{{name}}' hat ein nicht definiertes 'type'-Member!","propertyInvalidValue":"Ungultiger Eigenschaftswert '{{name}}'! Aktueller Wert: {{actualValue}}, Erwarteter Wert: {{value}}!","propertyInvalidValueType":"Ungultiger Eigenschaftswert '{{name}}'! Aktueller Wert: {{actualType}}, Erwarteter Wert: {{type}}!","elementNotInDOM":"Element existiert nicht in DOM! Bitte fugen Sie das Element zum DOM hinzu, bevor Sie eine Methode aufrufen.","moduleUndefined":"Modul ist nicht definiert.","missingReference":"{{elementType}}: Fehlender Verweis auf {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Browser unterstutzt keine HTMLTemplate-Elemente.","invalidTemplate":"{{elementType}}: '{{property}}' Die Eigenschaft akzeptiert eine Zeichenfolge, die mit der ID eines HTMLTemplate-Elements aus dem DOM ubereinstimmen muss.","accordionItemRequired":"{{elementType}}: '{{method}}' erfordert einen Artikel vom Typ \"smart-accordion-item\".","indexOutOfBound":"{{elementType}}: Nicht gebundener Index / Indizes in Methode '{{method}}'.","invalidSettings":"{{elementType}}: '{{method}}' Die Methode akzeptiert einen string oder ein Objekt als zweiten Parameter.","noItems":"{{elementType}}: Keine untergeordneten Elemente gefunden","overridingProperties":"{{elementType}}: Uberschreiben der Eigenschaften {{property1}} und {{property2}} angewendet. Die Eigenschaft '{{property1}}' wird standardmaessig verwendet."}}'></smart-accordion>

Set the messages property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.messages = {"en":{"propertyUnknownType":"'{{name}}' property is with undefined 'type' member!","propertyInvalidValue":"Invalid '{{name}}' property value! Actual value: {{actualValue}}, Expected value: {{value}}!","propertyInvalidValueType":"Invalid '{{name}}' property value type! Actual type: {{actualType}}, Expected type: {{type}}!","elementNotInDOM":"Element does not exist in DOM! Please, add the element to the DOM, before invoking a method.","moduleUndefined":"Module is undefined.","missingReference":"{{elementType}}: Missing reference to {{files}}.","htmlTemplateNotSuported":"{{elementType}}: Browser doesn't support HTMLTemplate elements.","invalidTemplate":"{{elementType}}: '{{property}}' property accepts a string that must match the id of an HTMLTemplate element from the DOM.","accordionItemRequired":"{{elementType}}: '{{method}}' requires an item from type \"smart-accordion-item\".","indexOutOfBound":"{{elementType}}: Out of bound index/indexes in '{{method}}' method.","invalidSettings":"{{elementType}}: '{{method}}' method accepts a string or an object as it's second parameter.","noItems":"{{elementType}}: No child elements found.","overridingProperties":"{{elementType}}: Overriding properties {{property1}} and {{property2}} applied. The '{{property1}}' property is used by default."}};

Get the messages property.

 const accordion = document.querySelector('smart-accordion');
 let messages = accordion.messages;

readonlyboolean

Indicates whether the element is read-only. When set to true, the element cannot be modified or interacted with by users; its value is fixed and user input is disabled. If false, the element remains editable and interactive.

Default value

false

Example

Set the readonly property.

 <smart-accordion readonly></smart-accordion>

Set the readonly property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.readonly = true;

Get the readonly property.

 const accordion = document.querySelector('smart-accordion');
 let readonly = accordion.readonly;

reorderboolean

Controls whether users can reorder accordion items by dragging and dropping them. When enabled, items within the accordion component can be rearranged interactively; when disabled, the order of items remains fixed.

Default value

false

Example

Set the reorder property.

 <smart-accordion reorder></smart-accordion>

Set the reorder property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.reorder = false;

Get the reorder property.

 const accordion = document.querySelector('smart-accordion');
 let reorder = accordion.reorder;

rightToLeftboolean

Specifies or retrieves a value that determines whether the element is aligned to accommodate right-to-left (RTL) languages and scripts, such as Arabic or Hebrew. This property ensures the element’s layout and text direction are properly adjusted to support RTL localization.

Default value

false

Example

Set the rightToLeft property.

 <smart-accordion right-to-left></smart-accordion>

Set the rightToLeft property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.rightToLeft = true;

Get the rightToLeft property.

 const accordion = document.querySelector('smart-accordion');
 let rightToLeft = accordion.rightToLeft;

themestring

Specifies the theme to be applied, which controls the overall appearance and visual style of the element, including aspects such as colors, fonts, and background.

Default value

""

Example

Set the theme property.

 <smart-accordion theme='blue'></smart-accordion>

Set the theme property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.theme = 'red';

Get the theme property.

 const accordion = document.querySelector('smart-accordion');
 let theme = accordion.theme;

unfocusableboolean

Specifies whether the element is capable of receiving keyboard focus, allowing users to navigate to it using the keyboard (such as the Tab key) and interact with it through assistive technologies.

Default value

false

Example

Set the unfocusable property.

 <smart-accordion unfocusable></smart-accordion>

Set the unfocusable property by using the HTML Element's instance.

 const accordion = document.querySelector('smart-accordion');
 accordion.unfocusable = false;

Get the unfocusable property.

 const accordion = document.querySelector('smart-accordion');
 let unfocusable = accordion.unfocusable;

Events

collapseCustomEvent

Triggered when an item has completed its collapse animation and is no longer expanded or visible. This event occurs only after the item is fully collapsed, ensuring that any associated transitions or content hiding have finished.

  • Bubbles Yes
  • Cancelable No
  • Interface CustomEvent
  • Event handler property onCollapse

Arguments

evCustomEvent
ev.detailObject
ev.detail.content - The collapsed item's content.
ev.detail.index - The index of the collapsed item.
ev.detail.label - The label of the collapsed item.

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of collapse event.

const accordion = document.querySelector('smart-accordion');
accordion.addEventListener('collapse', function (event) {
    const detail = event.detail,
        content = detail.content,
        index = detail.index,
        label = detail.label;

	// event handling code goes here.
})

collapsingCustomEvent

Fires immediately before an item begins its collapse animation, allowing you to perform actions or prevent the collapse from occurring.

  • Bubbles Yes
  • Cancelable Yes
  • Interface CustomEvent
  • Event handler property onCollapsing

Arguments

evCustomEvent
ev.detailObject
ev.detail.content - The item content.
ev.detail.index - The item's index.
ev.detail.label - The item's label.

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of collapsing event.

const accordion = document.querySelector('smart-accordion');
accordion.addEventListener('collapsing', function (event) {
    const detail = event.detail,
        content = detail.content,
        index = detail.index,
        label = detail.label;

	// event handling code goes here.
})

dragEndCustomEvent

Triggered when a user completes a drag-and-drop action to reorder items, indicating that the new order has been finalized and can be processed (e.g., saved or updated in the UI or backend).

  • Bubbles Yes
  • Cancelable Yes
  • Interface CustomEvent
  • Event handler property onDragEnd

Arguments

evCustomEvent
ev.detailObject
ev.detail.position - Current top and left coordinates of the dragged item.
ev.detail.target - The dragged item element.
ev.detail.content - The dragged item's content.
ev.detail.index - The dragged item's index.
ev.detail.label - The dragged item's label.

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of dragEnd event.

const accordion = document.querySelector('smart-accordion');
accordion.addEventListener('dragEnd', function (event) {
    const detail = event.detail,
        position = detail.position,
        target = detail.target,
        content = detail.content,
        index = detail.index,
        label = detail.label;

	// event handling code goes here.
})

dragStartCustomEvent

Fires when the user initiates a drag-and-drop reorder action, signaling the start of an item being moved within a sortable list or container. This event provides an opportunity to perform setup tasks, such as highlighting the item being dragged or preparing the UI for reordering.

  • Bubbles Yes
  • Cancelable Yes
  • Interface CustomEvent
  • Event handler property onDragStart

Arguments

evCustomEvent
ev.detailObject
ev.detail.position - Initial top and left coordinates of the item being dragged.
ev.detail.target - The item element being dragged.
ev.detail.content - The dragged item's content.
ev.detail.index - The dragged item's index.
ev.detail.label - The dragged item's label.

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of dragStart event.

const accordion = document.querySelector('smart-accordion');
accordion.addEventListener('dragStart', function (event) {
    const detail = event.detail,
        position = detail.position,
        target = detail.target,
        content = detail.content,
        index = detail.index,
        label = detail.label;

	// event handling code goes here.
})

expandCustomEvent

Triggered when an item has completed its expansion and is fully visible to the user. This event occurs after any expansion animations or transitions have finished, ensuring that the item's contents are now accessible for interaction.

  • Bubbles Yes
  • Cancelable No
  • Interface CustomEvent
  • Event handler property onExpand

Arguments

evCustomEvent
ev.detailObject
ev.detail.position - Current top and left coordinates of the expanded item.
ev.detail.target - The expanded item element.
ev.detail.content - The expanded item's content.
ev.detail.index - The expanded item's index.
ev.detail.label - The expanded item's label.

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of expand event.

const accordion = document.querySelector('smart-accordion');
accordion.addEventListener('expand', function (event) {
    const detail = event.detail,
        position = detail.position,
        target = detail.target,
        content = detail.content,
        index = detail.index,
        label = detail.label;

	// event handling code goes here.
})

expandingCustomEvent

Fires immediately before an item begins its expansion process, allowing you to perform actions or modify data right before the expansion occurs. This event provides an opportunity to prevent the expansion or make adjustments as needed.

  • Bubbles Yes
  • Cancelable Yes
  • Interface CustomEvent
  • Event handler property onExpanding

Arguments

evCustomEvent
ev.detailObject
ev.detail.content - The content of the item being expanded.
ev.detail.index - The index of the item being expanded.
ev.detail.label - The label of the item being expanded.

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of expanding event.

const accordion = document.querySelector('smart-accordion');
accordion.addEventListener('expanding', function (event) {
    const detail = event.detail,
        content = detail.content,
        index = detail.index,
        label = detail.label;

	// event handling code goes here.
})

Methods

collapse( position: number): void

Collapses the item located at the specified index, hiding its associated content or details from view. This action typically updates the user interface to indicate that the item is no longer expanded.

Arguments

positionnumber

Index of the item to collapse.


Invoke the collapse method.

const accordion = document.querySelector('smart-accordion');
accordion.collapse(0);

Try a demo showcasing the collapse method.

expand( position: number): void

Expands the item located at the specified index in the collection, making its detailed content visible or accessible to the user.

Arguments

positionnumber

Index of the item to expand.


Invoke the expand method.

const accordion = document.querySelector('smart-accordion');
accordion.expand(0);

Try a demo showcasing the expand method.

insert( index: number, item: any): void

Inserts a new item into the array at the specified index, shifting existing elements to the right to accommodate the new entry. If the specified index is out of range, the operation will either append the item to the end or return an error, depending on the implementation.

Arguments

indexnumber

Index where the new item will be inserted.

itemany

Object representing the new item's properties.


Invoke the insert method.

const accordion = document.querySelector('smart-accordion');
accordion.insert("0, {\"label\":\"New item\",\"content\":\"New item content\" }");

Try a demo showcasing the insert method.

removeAt( position: number): void

Removes the item located at the specified index from the array, shifting subsequent items one position to the left. The array's length is reduced by one, and the removed item is no longer accessible.

Arguments

positionnumber

Index of the item to remove.


Invoke the removeAt method.

const accordion = document.querySelector('smart-accordion');
accordion.removeAt("0");

Try a demo showcasing the removeAt method.

update( index: number, settings: any): void

Replaces the item at the given index in the collection with an updated version, incorporating the specified new property values while preserving any unchanged properties.

Arguments

indexnumber

Index of the item to update.

settingsany

Object containing updated property values for the item.


Invoke the update method.

const accordion = document.querySelector('smart-accordion');
accordion.update("0, {\"label\":\"Updated item\",\"content\":\"Updated item content\" }");

Try a demo showcasing the update method.

CSS Variables

--smart-accordion-animation-durationvar()

Default value

"225ms"

smartAccordion animation duration

--smart-accordion-default-widthvar()

Default value

"var(--smart-box-width)"

smartAccordion default width

--smart-accordion-default-heightvar()

Default value

"var(--smart-box-height)"

smartAccordion default height

--smart-accordion-expanded-content-heightvar()

Default value

"0px"

Determines expanded content's height

--smart-accordion-expanded-content-local-heightvar()

Default value

"0px"

The height of an expanded item content part. Calculated dynamically for each item. Used in all modes except 'singleFitHeight'.

--smart-accordion-item-header-heightvar()

Default value

"var(--smart-bar-height)"

Element's header height. Used in several calcilations related to items height.

--smart-accordion-item-expanded-offsetvar()

Default value

"20px"

An offset below each expanded accordion item.


AccordionItem

Single item in an Accordion view.

Selector

smart-accordion-item

Properties

AarrowSpecifies or retrieves the position of the arrow indicator within the header. Accepts values such as 'left', 'right', or 'none'. When set to 'none', the arrow will not be displayed in the header.
CcontentSets or retrieves the content of the item. Use this property to assign new content to the item or to access its current content value.
EexpandedGets or sets whether the element is in its expanded or collapsed state. When set to true, the element is expanded and its content is visible; when false, the element is collapsed and its content is hidden.
FfocusedGets or sets whether the element currently has input focus. When set to true, the element receives focus; when set to false, the element loses focus. This property reflects the element's current focus state within the user interface.
LlabelSets or retrieves the label of the item. This property allows you to assign a descriptive name to the item or access its current label.

Events

CcollapseThis event is triggered whenever the item transitions from an expanded to a collapsed state, typically as a result of user interaction or a programmatic action. Use this event to execute custom logic or update the UI when the item is hidden or minimized.
EexpandThis event is triggered when a user expands an item, such as clicking to reveal additional content or details. It typically occurs after the expansion animation or transition is complete, indicating that the item is now fully visible. Use this event to perform actions that should only occur once the item has been expanded, such as loading related data or updating the user interface.

Properties

arrow"left" | "right" | "none"

Specifies or retrieves the position of the arrow indicator within the header. Accepts values such as 'left', 'right', or 'none'. When set to 'none', the arrow will not be displayed in the header.

Default value

"left"

Example

Set the arrow property.

 <smart-accordion-item arrow='right'></smart-accordion-item>

Set the arrow property by using the HTML Element's instance.

 const accordionitem = document.querySelector('smart-accordion-item');
 accordionitem.arrow = 'none';

Get the arrow property.

 const accordionitem = document.querySelector('smart-accordion-item');
 let arrow = accordionitem.arrow;

contentstring | HTMLElement

Sets or retrieves the content of the item. Use this property to assign new content to the item or to access its current content value.

Default value

''

Example

Set the content property.

 <smart-accordion-item content='Content'></smart-accordion-item>

Set the content property by using the HTML Element's instance.

 const accordionitem = document.querySelector('smart-accordion-item');
 accordionitem.content = New Content;

Get the content property.

 const accordionitem = document.querySelector('smart-accordion-item');
 let content = accordionitem.content;

expandedboolean

Gets or sets whether the element is in its expanded or collapsed state. When set to true, the element is expanded and its content is visible; when false, the element is collapsed and its content is hidden.

Default value

false

Example

Set the expanded property.

 <smart-accordion-item expanded></smart-accordion-item>

Set the expanded property by using the HTML Element's instance.

 const accordionitem = document.querySelector('smart-accordion-item');
 accordionitem.expanded = false;

Get the expanded property.

 const accordionitem = document.querySelector('smart-accordion-item');
 let expanded = accordionitem.expanded;

focusedboolean

Gets or sets whether the element currently has input focus. When set to true, the element receives focus; when set to false, the element loses focus. This property reflects the element's current focus state within the user interface.

Default value

false

Example

Set the focused property.

 <smart-accordion-item focused></smart-accordion-item>

Set the focused property by using the HTML Element's instance.

 const accordionitem = document.querySelector('smart-accordion-item');
 accordionitem.focused = false;

Get the focused property.

 const accordionitem = document.querySelector('smart-accordion-item');
 let focused = accordionitem.focused;

labelstring

Sets or retrieves the label of the item. This property allows you to assign a descriptive name to the item or access its current label.

Default value

""

Example

Set the label property.

 <smart-accordion-item label='Label'></smart-accordion-item>

Set the label property by using the HTML Element's instance.

 const accordionitem = document.querySelector('smart-accordion-item');
 accordionitem.label = 'New Label';

Get the label property.

 const accordionitem = document.querySelector('smart-accordion-item');
 let label = accordionitem.label;

Events

collapseCustomEvent

This event is triggered whenever the item transitions from an expanded to a collapsed state, typically as a result of user interaction or a programmatic action. Use this event to execute custom logic or update the UI when the item is hidden or minimized.

  • Bubbles Yes
  • Cancelable No
  • Interface CustomEvent
  • Event handler property onCollapse

Arguments

evCustomEvent

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of collapse event.

const accordionitem = document.querySelector('smart-accordion-item');
accordionitem.addEventListener('collapse', function (event) {
	// event handling code goes here.
})

expandCustomEvent

This event is triggered when a user expands an item, such as clicking to reveal additional content or details. It typically occurs after the expansion animation or transition is complete, indicating that the item is now fully visible. Use this event to perform actions that should only occur once the item has been expanded, such as loading related data or updating the user interface.

  • Bubbles Yes
  • Cancelable No
  • Interface CustomEvent
  • Event handler property onExpand

Arguments

evCustomEvent

Methods

isDefaultPrevented

Returns true if the event was prevented by any of its subscribers.

Returns

boolean true if the default action was prevented. Otherwise, returns false.

preventDefault

The preventDefault() method prevents the default action for a specified event. In this way, the source component suppresses the built-in behavior that follows the event.

stopPropagation

The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases.

Example

Set up the event handler of expand event.

const accordionitem = document.querySelector('smart-accordion-item');
accordionitem.addEventListener('expand', function (event) {
	// event handling code goes here.
})