Section

There is a breaking change to this component in the next version of NUI Widgets.
import { Section } from '@concur/nui-widgets';

Section components provide an easy way to define sections of a page. They have properly rendered headings and children and are accessible to visually impaired users. They should be used as a fundamental building block of page design.

Introduction

For designers, Section components provide an easy way to visually define sections of a page with properly rendered headings and children, as seen in the following example:

const toolbar = (
    <ButtonToolbar muted>
        <ControlLabel>Title Content:</ControlLabel>
        <Button type='link'>Link</Button>
    </ButtonToolbar>
);
<Section
    title='Section Title'
    titleContent={toolbar}
    titleContentAlignment='left' >
    <p>Child Content</p>
</Section>

For developers, Section components provide an easy way to semantically define sections of a page using <section>, <header> and <h#> HTML elements. For example, the following semantically meaningful HTML:

<section>
   <header>
      <h2>Section Title</h2>
   </header>
   <p>Child Content</p>
</section>

is easily generated by:

<Section title="Section Title">
   <p>Child Content<p>
</Section>

The above HTML elements provide important accessibility information and aid screen readers when parsing a page’s structure and content.

Examples

Default

Rendering with the only two required properties, title and children (which is implicitly constructed by React).

<Section
    title='h2 (default)'>
    {paragraph}
</Section>

Title Content

titleContent={toolbar}, headingLevel='h4'

Title content is anything intended to sit aligned with and to the right of the title. This is often used for toolbars, status information, or links. Note that the title content is right-aligned within the section by default.

Title content can be used to make a “custom” heading. The title property is used for providing simple text that improves accessibility. If the design favors complicated text as the visual heading, set the titleIsHidden property to true and put the custom node in the titleContent property and set titleContentAlignment to left.

<Section
    headingLevel='h4'
    title='h4, toolbar title content aligned right'
    titleContent={toolbar}>
    {paragraph}
</Section>

Icons

iconName='icon-air'

This example demonstrates both the titleIsHidden property and the iconName property. Regardless of the value of titleIsHidden, any section icon will always be visible. (Icon adornments like these have no audible description and are therefore invisible to screen readers.) A list of available icon names can be found at Icons.

<Section
    iconName='icon-air'
    title='Hidden From Sight, Visible To Screen Readers...'
    titleContent={toolbar}
    titleIsHidden>
    {paragraph}
</Section>

Type 2

Type 2 sections are essentially the same as the original type 1 sections with (very few) minor differences in markup and some significant differences in styling. Type 2 sections are often used in SAP Concur’s Travel product. Allowable values for type are '1' and '2' (and it’s possible that more types will be added in the future).

type='2', iconName='icon-star', titleContent={button}

Note that when a type 2 section is assigned an icon, the child elements are indented even further to ensure that they continue to align with the beginning of the title. One very important point to note with regard to type 2 sections: their headings all render exactly the same, no matter what semantic heading level you assign to them. <h2> through <h6> are all visually rendered the same: uppercase, bold, body font size. (However, it’s still important to assign them the appropriate semantic heading level to aid screen readers and visually impaired users.)

<Section
    iconName='icon-star'
    title='h2, type 2, icon (star), link button as title content'
    titleContent={button}
    type='2'>
    {paragraph}
</Section>

Expandable

See SectionExpandable.

Usage

Properties

Section components accept the following properties; see below to understand how these properties affect the generated HTML.

Name Type Default Description
children Any Required The “body” of the section; that is, any content that exists outside the <header> element but inside the <section> element.
title String Required Plain text of the section heading. Must not contain only whitespace because concise yet descriptive headings are extremely important to screen readers. If this needs to be visually hidden, set the titleIsHidden property to true.
className String   Sets the class attribute for the entire section: <section class="cnqr-my-class">. If not set, no class attribute will be written: <section>.
headingLevel String 'h2' Sets the semantic heading level for the section heading: <h3>. Allowable values are 'h2' through 'h6'. (<h1> headings are managed by the framework itself.)
iconName String   If set, an icon will be displayed to the left of the title text (and will be visible even when titleIsHidden is true). A list of available icons and their corresponding names can be found at Icons.
titleContent Any   Any content that resides to the right of the heading. Most often this will be used for buttons, status information, or other toolbar-like controls. It will normally align with the vertical center of the <h#> element, but will wrap beneath if necessary.
titleContentAlignment String 'right' Defines whether titleContent will be left- or right-justified after the initial <h#> heading. Allowable values are 'left' and 'right'.
titleIsHidden Boolean false If true, the title text will be hidden from sighted readers but will remain accessible to screen readers.
type String '1' Allowable values are '1' and '2'. If '2', a more visually stylized component will be used (though the underlying markup will be virtually identical). Type 2 sections are often used in SAP Concur’s Travel product. See above for examples of type 2 components.

Generated HTML

The following demonstrates how each of the above properties fit into the generated HTML. The only two required properties are title (the heading text) and the implicit children (the child content); all other properties are optional:

<Section
   title='My Heading'
   className='cnqr-my-section'
   headingLevel='h3'
   iconName='icon-star'
   titleContent={button}
   titleContentAlignment='left'
   titleIsHidden
   type='1'>
   <p>This is my child content</p>
</Section>

This generates the following HTML:

<section class="cnqr-my-section">
   <header class="cnqr-align-left">
      <h3><i class="icon-star"></i><span class="screen-reader-only">My Heading</span></h3>
      <div>
         {button}
      </div>
   </header>
   <p>This is my child content</p>
</section>

Note that it’s possible to place Section components inside of other Section components, which makes it easy to create correctly structured pages (see also the Nested Sections example):

<Section title='Outer Content' headingLevel='h2'>
   <Section title='Inner Content Section 1' headingLevel='h3'/>
   <Section title='Inner Content Section 2' headingLevel='h3'/>
   <Section title='Inner Content Section 3' headingLevel='h3'>
     <Section title='Innermost Content' headingLevel='h4'/>
   </Section>
</Section>

Accessibility

Important considerations with regard to accessibility and the Section component:

  • The use of Section components naturally leads to well-structured and accessible HTML.
  • Nesting Section components within Section components naturally leads to well-structured and accessible pages, as outlined in the example, above.
  • title is relied upon by the visually impaired; titles should be concise, yet accurate and descriptive. They must be renderable as plain text and should not contain control elements of any sort, such as buttons or drop-down lists – that’s what the titleContent property is for.
  • headingLevel values must be properly selected to create valid HTML structures. An <h2> section cannot reside as a child inside a parent <h3> section, for example; the opposite order is correct.
  • titleContent is unlikely to contain Section components (or anything that generates an <h#> heading). If you find yourself doing this then you quite likely need to re-think your structure.

Resources