Tree

Mostrar parámetros

Parámetros del componente

              params:
- name: type
  type: string
  required: false
  description: Type of input control to render. Admitted values are `navigation`, `checkbox` and `radio` or not set. Defaults to `radio`.
- name: searchbar
  type: component
  required: false
  description: A searchbar component to filter the items. Inherits all the searchbar component params.
- name: ariaLabel
  type: text
  required: false
  description: aria-label for nav tag. Should be a description of tree type navigation.
- name: hasUnderline
  type: boolean
  required: false
  description: If `true`, all items will be underlined except the disabled ones or the ones that have no href.
- name: describedBy
  type: string
  required: false
  description: One or more element IDs to add to the input `aria-describedby` attribute without a fieldset, used to provide additional descriptive information for screenreader users.
- name: fieldset
  type: object
  required: false
  description: Options for the fieldset component (e.g. legend).
  isComponent: true
- name: hint
  type: object
  required: false
  description: Options for the hint component (e.g. text).
  isComponent: true
- name: errorMessage
  type: object
  required: false
  description: Options for the error message component. The error message component will not display if you use a falsy value for `errorMessage`, for example `false` or `null`.
  isComponent: true
- name: formGroup
  type: object
  required: false
  description: Options for the form-group wrapper
  params:
  - name: classes
    type: string
    required: false
    description: Classes to add to the form group (e.g. to show error state for the whole group)
- name: idPrefix
  type: string
  required: false
  description: String to prefix id for each item if no id is specified on each item.
- name: name
  type: string
  required: true
  description: Name attribute for all checkbox/radio items.
- name: heading
  type: object
  required: true
  description: Options for the heading
  params:
  - name: text
    type: string
    required: true
    description: If `html` is set, this is not required. Text to use within the heading. If `html` is provided, the `text` argument will be ignored.
  - name: html
    type: string
    required: true
    description: If `text` is set, this is not required. HTML to use within the heading. If `html` is provided, the `text` argument will be ignored.
  - name: classes
    type: string
    required: false
    description: Classes to add to the heading.
  - name: id
    type: string
    required: false
    description: Specific id attribute for the component. If omitted, then idPrefix option will be applied.
- name: headingLevel
  type: number
  required: false
  description: If headingLevel is 1, the parent heading tag needed inside this component will be a h1, if 2 will be a h2, and so on.
- name: items
  type: array
  required: true
  description: Array of tree items objects.
  params:
  - name: text
    type: string
    required: true
    description: If `html` is set, this is not required. Text to use within each tree item label. If `html` is provided, the `text` argument will be ignored.
  - name: html
    type: string
    required: true
    description: If `text` is set, this is not required. HTML to use within each tree item label. If `html` is provided, the `text` argument will be ignored.
  - name: href
    type: string
    required: false
    description: Item link in tree type navigation.
  - name: id
    type: string
    required: false
    description: Specific id attribute for the item. If omitted, then idPrefix option will be applied.
  - name: name
    type: string
    required: true
    description: Specific name for the checkbox/radio item. If omitted, then component global `name` string will be applied.
  - name: value
    type: string
    required: true
    description: Value for the checkbox/radio input.
  - name: label
    type: object
    required: false
    description: Provide attributes and classes to each checkbox/radio item label.
    isComponent: true
  - name: hint
    type: object
    required: false
    description: Provide hint to each checkbox/radio item.
    isComponent: true
  - name: checked
    type: boolean
    required: false
    description: If true, checkbox/radio will be checked.
  - name: isIndeterminate
    type: boolean
    required: false
    description: If true, the checkbox will have an additional indeterminate state to show a partial true. Only for checkbox item.
  - name: indeterminateChecked
    type: boolean
    required: false
    description: If true, the checkbox will have an indeterminate checked initial state. This will override isChecked value. Only for checkbox item.
  - name: disabled
    type: boolean
    required: false
    description: If true, tree will be disabled.
  - name: classes
    type: string
    required: false
    description: Classes to add to the item.
  - name: attributes
    type: object
    required: false
    description: HTML attributes (for example data attributes) to add to the item.
  - name: expanded
    type: boolean
    required: false
    description: If true, tree sub will be expanded.
  - name: sub
    type: boolean
    required: false
    description: If true, content provided will be revealed when the item is expanded.
  - name: sub.classes
    type: string
    required: false
    description: Classes to add to the sub container.
  - name: sub.attributes
    type: string
    required: false
    description: HTML attributes (for example data attributes) to add to the sub container.
  - name: sub.items
    type: array
    required: false
    description: Provide subitems for the sub reveal. Each items have same params as this item.
- name: classes
  type: string
  required: false
  description: Classes to add to the tree container.
- name: attributes
  type: object
  required: false
  description: HTML attributes (for example data attributes) to add to the tree container.
              
            

Por defecto

Selecciona organismo
Mostrar códigodel ejemplo: Por defecto

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "por-defecto",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "idPrefix": "default-example",
  "items": [
    {
      "text": "Item 1",
      "id": "default-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "default-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "default-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "default-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "default-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "default-example-item-3"
        }
      }
    }
  ]
}) }}

Tipo checkbox

Selecciona organismo
Mostrar códigodel ejemplo: Tipo checkbox

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "type-checkbox",
  "classes": "mt-base",
  "type": "checkbox",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "idPrefix": "type-checkbox",
  "items": [
    {
      "text": "Item 1",
      "id": "type-checkbox-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "type-checkbox-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "type-checkbox-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "type-checkbox-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "type-checkbox-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "type-checkbox-example-item-3"
        }
      }
    }
  ]
}) }}

Tree navigation

Mostrar códigodel ejemplo: Tree navigation

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "tree-nav",
  "classes": "mt-base",
  "type": "navigation",
  "idPrefix": "navigation-example",
  "ariaLabel": "Apartados de esta página",
  "items": [
    {
      "text": "Item 1",
      "id": "navigation-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1",
                  "href": "#"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2",
                  "href": "#"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3",
                  "href": "#",
                  "active": true
                }
              ],
              "attributes": {
                "aria-labelledby": "navigation-example-item-3"
              }
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "navigation-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#"
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "navigation-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#"
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-example-item-3"
        }
      }
    }
  ]
}) }}

Tree navigation con hasunderline

Usa "hasUnderline": true cuando tienes mezclados, items deshabilitados o sin href e items normales.

Mostrar códigodel ejemplo: Tree navigation con hasunderline

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "tree-nav-hasunderline",
  "classes": "mt-base",
  "type": "navigation",
  "idPrefix": "navigation-hasunderline-example",
  "ariaLabel": "Apartados de esta página",
  "hasUnderline": "true",
  "items": [
    {
      "text": "Item 1",
      "id": "navigation-hasunderline-example-item-1",
      "href": "#",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2 deshabilitado o sin href",
            "value": "subitem-2",
            "href": "#",
            "disabled": true
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1",
                  "href": "#"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2",
                  "href": "#"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3",
                  "href": "#",
                  "active": true
                }
              ],
              "attributes": {
                "aria-labelledby": "navigation-hasunderline-example-item-3"
              }
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-hasunderline-example-item-1"
        }
      }
    },
    {
      "text": "Item 2 deshabilitado o sin href",
      "id": "navigation-hasunderline-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2 deshabilitado o sin href",
            "value": "subitem-2",
            "href": "#",
            "disabled": true
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#"
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-hasunderline-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "navigation-hasunderline-example-item-3",
      "href": "#",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#"
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-hasunderline-example-item-3"
        }
      }
    }
  ]
}) }}

Usa el parámetro "classes": "c-link" en cada item para dar apariencia más visible de links.

Mostrar códigodel ejemplo: Tree navigation link

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "tree-nav-link",
  "classes": "mt-base",
  "type": "navigation",
  "idPrefix": "navigation-link-example",
  "ariaLabel": "Apartados de esta página",
  "items": [
    {
      "text": "Item 1",
      "id": "navigation-link-example-item-1",
      "classes": "c-link",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#",
            "classes": "c-link"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#",
            "classes": "c-link"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "classes": "c-link",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1",
                  "href": "#",
                  "classes": "c-link"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2",
                  "href": "#",
                  "classes": "c-link"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3",
                  "href": "#",
                  "active": true,
                  "classes": "c-link"
                }
              ],
              "attributes": {
                "aria-labelledby": "navigation-link-example-item-3"
              }
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-link-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "classes": "c-link",
      "id": "navigation-link-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#",
            "classes": "c-link"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#",
            "classes": "c-link"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#",
            "classes": "c-link"
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-link-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "classes": "c-link",
      "id": "navigation-link-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#",
            "classes": "c-link"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#",
            "classes": "c-link"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#",
            "classes": "c-link"
          }
        ],
        "attributes": {
          "aria-labelledby": "navigation-link-example-item-3"
        }
      }
    }
  ]
}) }}

Tree nav: mostrar activo un item del tree con javascript

Puedes usar con javascript la función global activateItemsTree(tree, element, true), para mostrar un item activo del tree nav. Ej: Abre la consola del navegador y escribe activateItemsTree("tree-nav-js", "sub-sub-tree-nav-js-item-1-2-1", true) para mostrar un item del menú activo.

Mostrar códigodel ejemplo: Tree nav: mostrar activo un item del tree con javascript

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "tree-navigation-js",
  "classes": "mt-base",
  "id": "tree-nav-js",
  "type": "navigation",
  "idPrefix": "tree-nav-js-example",
  "items": [
    {
      "text": "Item 1",
      "id": "tree-nav-js-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "index.html"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1",
                  "href": "#"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2",
                  "href": "#"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3",
                  "href": "#"
                }
              ],
              "attributes": {
                "aria-labelledby": "tree-nav-js-item-3"
              }
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "tree-nav-js-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "tree-nav-js-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#"
          }
        ],
        "attributes": {
          "aria-labelledby": "tree-nav-js-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "tree-nav-js-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "href": "#"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "href": "#"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "href": "#"
          }
        ],
        "attributes": {
          "aria-labelledby": "tree-nav-js-item-3"
        }
      }
    }
  ]
}) }}

Con pista y error

Selecciona organismo

Selecciona el organismo al que perteneces.

Error:Error: No tienes permiso para seleccionar ese organismo.

Mostrar códigodel ejemplo: Con pista y error

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "with-hint-and-error",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "errorMessage": {
    "text": "Error: No tienes permiso para seleccionar ese organismo."
  },
  "idPrefix": "with-hint-and-error",
  "items": [
    {
      "text": "Item 1",
      "id": "with-hint-and-error-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-hint-and-error-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-hint-and-error-example-item-2",
      "checked": true,
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-hint-and-error-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-hint-and-error-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-hint-and-error-example-item-3"
        }
      }
    }
  ]
}) }}

Con item deshabilitado

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con item deshabilitado

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "with-disabled-item",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "with-disabled-item",
  "items": [
    {
      "text": "Item 1",
      "id": "with-disabled-item-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-disabled-item-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-disabled-item-example-item-2",
      "disabled": true,
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "disabled": true
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-disabled-item-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-disabled-item-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-disabled-item-example-item-3"
        }
      }
    }
  ]
}) }}

Con item activo

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con item activo

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "with-active-item",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "with-active-item",
  "items": [
    {
      "text": "Item 1",
      "id": "with-active-item-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-active-item-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-active-item-example-item-2",
      "active": true,
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-active-item-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-active-item-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-active-item-example-item-3"
        }
      }
    }
  ]
}) }}

Con pistas en items

Selecciona organismo
Mostrar códigodel ejemplo: Con pistas en items

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "with-hints-on-items",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "idPrefix": "with-hints-on-items",
  "items": [
    {
      "text": "Item 1",
      "hint": {
        "text": "Pista en item"
      },
      "id": "with-hints-on-items-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "hint": {
              "text": "Pista en item"
            }
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "hint": {
              "text": "Pista en item"
            }
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "hint": {
              "text": "Pista en item"
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "with-hints-on-items-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "hint": {
        "text": "Pista en item"
      },
      "id": "with-hints-on-items-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "hint": {
              "text": "Pista en item"
            }
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "hint": {
              "text": "Pista en item"
            }
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "hint": {
              "text": "Pista en item"
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "with-hints-on-items-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-hints-on-items-example-item-3",
      "hint": {
        "text": "Pista en item"
      },
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1",
            "hint": {
              "text": "Pista en item"
            }
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2",
            "hint": {
              "text": "Pista en item"
            }
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3",
            "hint": {
              "text": "Pista en item"
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "with-hints-on-items-example-item-3"
        }
      }
    }
  ]
}) }}

Con un texto de item muy largo

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con un texto de item muy largo

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "with-very-long-option-text",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "with-very-long-option-text",
  "items": [
    {
      "text": "Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus.",
      "id": "with-very-long-option-text-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus.",
            "value": "subitem-1"
          },
          {
            "text": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras mattis consectetur purus sit amet fermentum.",
            "value": "subitem-2"
          },
          {
            "text": "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. Sed posuere consectetur est at lobortis.",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-very-long-option-text-example-item-1"
        }
      }
    },
    {
      "text": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras mattis consectetur purus sit amet fermentum.",
      "id": "with-very-long-option-text-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus.",
            "value": "subitem-1"
          },
          {
            "text": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras mattis consectetur purus sit amet fermentum.",
            "value": "subitem-2"
          },
          {
            "text": "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. Sed posuere consectetur est at lobortis.",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-very-long-option-text-example-item-2"
        }
      }
    },
    {
      "text": "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. Sed posuere consectetur est at lobortis.",
      "id": "with-very-long-option-text-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Nullam id dolor id nibh ultricies vehicula ut id elit. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Maecenas faucibus mollis interdum. Donec id elit non mi porta gravida at eget metus.",
            "value": "subitem-1"
          },
          {
            "text": "Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Donec sed odio dui. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aenean eu leo quam. Pellentesque ornare sem lacinia quam venenatis vestibulum. Cras mattis consectetur purus sit amet fermentum.",
            "value": "subitem-2"
          },
          {
            "text": "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Praesent commodo cursus magna, vel scelerisque nisl consectetur et. Etiam porta sem malesuada magna mollis euismod. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. Sed posuere consectetur est at lobortis.",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-very-long-option-text-example-item-3"
        }
      }
    }
  ]
}) }}

Con un legend como encabezado

Selecciona organismo

Mostrar códigodel ejemplo: Con un legend como encabezado

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "with-legend-as-page-heading",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo",
      "classes": "c-h2",
      "isPageHeading": true
    },
    "headingLevel": 2
  },
  "idPrefix": "with-legend-as-page-heading",
  "items": [
    {
      "text": "Item 1",
      "id": "with-legend-as-page-heading-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-legend-as-page-heading-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-legend-as-page-heading-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-legend-as-page-heading-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-legend-as-page-heading-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "with-legend-as-page-heading-example-item-3"
        }
      }
    }
  ]
}) }}

Sin fieldset

Mostrar códigodel ejemplo: Sin fieldset

Contenido

Nunjucks macro

{% from "components/tree/_macro.tree.njk" import componentTree %}

{{ componentTree({
  "name": "without-fieldset",
  "idPrefix": "without-fieldset",
  "items": [
    {
      "text": "Item 1",
      "id": "without-fieldset-example-item-1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "without-fieldset-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "without-fieldset-example-item-2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "without-fieldset-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "without-fieldset-example-item-3",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "without-fieldset-example-item-3"
        }
      }
    }
  ]
}) }}