Base Lightning Components Considerations

Learn about the guidelines on using the base Lightning components.

We recommend that you don't depend on the markup of a Lightning component as its internals can change in the future. For example, using cmp.get("v.body") and examining the DOM elements can wreak havoc should the component markup change down the road. With LockerService enforced, you won't be able to traverse the DOM for components you don't own. Instead of accessing the DOM tree, you can rely on the component tree and take advantage of value binding with component attributes. For example, you'll go far with cmp.find("myInput").get("") instead of cmp.find("myInput").getElement().name.

Many of the base Lightning components are still evolving and the following considerations can help you while you’re building your apps.

lightning:buttonMenu (Beta)
This component contains menu items that are created only if the button is triggered. You won’t be able to reference the menu items during initialization or if the button isn’t triggered yet.
lightning:formattedDateTime (Beta)
This component provides fallback behavior in Apple Safari 10 and below. The following formatting options have exceptions when using the fallback behavior in older browsers.
  • era is not supported.
  • timeZoneName appends GMT for short format, GMT-h:mm or GMT+h:mm for long format.
  • timeZone supports UTC. If another timezone value is used, lightning:formattedDateTime uses the browser timezone.
lightning:formattedNumber (Beta)
This component provides the following fallback behavior in Apple Safari 10 and below.
  • If style is set to currency, providing a currencyCode value that’s different from the locale displays the currency code instead of the symbol. The following example displays EUR12.34 in fallback mode and €12.34 otherwise.
    <lightning:formattedNumber value="12.34" style="currency" 
  • currencyDisplayAs supports symbol only. The following example displays $12.34 in fallback mode only if the currencyCode matches the user’s locale currency and USD12.34 otherwise.
    <lightning:formattedNumber value="12.34" style="currency" 
     currencyCode="USD" currencyDisplayAs="symbol"/>
lightning:input (Beta)
The file type is not supported. Also, date pickers are available in the following components but they don’t inherit the Lightning Design System styling.
  • <lightning:input type="date" />
  • <lightning:input type="datetime-local" />
Fields for percentage and currency input must specify a step increment of 0.01 as required by the native implementation.
<lightning:input type="number" name="percentVal" label="Enter a percentage value" formatter="percent" step="0.01" />
<lightning:input type="number" name="currencyVal" label="Enter a dollar amount" formatter="currency" step="0.01" />
When working with checkboxes, radio buttons, and toggle switches, use aura:id to group and traverse the array of components. Grouping them enables you to use get("v.checked") to determine which elements are checked or unchecked without reaching into the DOM. You can also use the name and value attributes to identify each component during the iteration. The following example groups three checkboxes together using aura:id.
        <legend>Select your favorite color:</legend>
        <lightning:input type="checkbox" label="Red" 
            name="color1" value="1" aura:id="colors"/>
        <lightning:input type="checkbox" label="Blue" 
            name="color2" value="2" aura:id="colors"/>
        <lightning:input type="checkbox" label="Green" 
            name="color3" value="3" aura:id="colors"/>
    <lightning:button label="Submit" onclick="{!c.submitForm}"/>
In your client-side controller, you can retrieve the array using cmp.find("colors") and inspect the checked values.
lightning:tab (Beta)
This component creates its body during runtime. You won’t be able to reference the component during initialization. Referencing the component using aura:id might return unexpected results, such as the component returning an undefined value when implementing cmp.find("myComponent").
lightning:tabset (Beta)
When you load more tabs than can fit the width of the viewport, the tabset provides navigation buttons that scrolls horizontally to display the overflow tabs.