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 `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: 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: 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.

accessibilityCriteria: |
  ## sub reveals
  Must:
  - be visible as static content if JavaScript is unavailable or fails
  - be hidden if JavaScript is available and is collapsed
  - indicate if content is expanded or collapsed
  - indicate that there is collapsed content to interact with

  Note that alphagov have known issues against this criteria: https://github.com/alphagov/govuk_elements/issues/575
              
            

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",
  "id": "tree-default",
  "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"
        }
      }
    }
  ]
}) }}

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"
        }
      }
    }
  ]
}) }}

Con todo items padres

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con todo items padres

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-all-parent-items",
  "classes": "mt-base",
  "type": "checkbox",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "parent-example",
  "items": [
    {
      "text": "Item 1",
      "id": "parent-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": "parent-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "parent-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": "parent-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "parent-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": "parent-example-item-3"
        }
      }
    }
  ]
}) }}

Con un item padre abierto

Usa "expanded": true

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con un item padre abierto

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-a-parent-item-opened",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "tree-item",
  "items": [
    {
      "text": "Item 1",
      "id": "tree-item-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": "tree-item-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "tree-item-item-2",
      "expanded": true,
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ],
        "attributes": {
          "aria-labelledby": "tree-item-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "tree-item-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": "tree-item-item-3"
        }
      }
    }
  ]
}) }}

Con muchos niveles de profundidad

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con muchos niveles de profundidad

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-many-depth-levels",
  "classes": "mt-base",
  "id": "tree-item-deep",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "tree-item-nodes",
  "items": [
    {
      "text": "Item 1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ]
      }
    },
    {
      "text": "Item 2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ]
      }
    },
    {
      "text": "Item 3",
      "expanded": true,
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3"
                }
              ]
            }
          },
          {
            "text": "Subitem 2",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3"
                }
              ]
            }
          },
          {
            "text": "Subitem 3",
            "expanded": true,
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3",
                  "expanded": true,
                  "sub": {
                    "items": [
                      {
                        "text": "Subitem 1",
                        "sub": {
                          "items": [
                            {
                              "text": "Subitem 1",
                              "value": "subitem-1"
                            },
                            {
                              "text": "Subitem 2",
                              "value": "subitem-2"
                            },
                            {
                              "text": "Subitem 3",
                              "value": "subitem-3"
                            }
                          ]
                        }
                      },
                      {
                        "text": "Subitem 2",
                        "sub": {
                          "items": [
                            {
                              "text": "Subitem 1",
                              "value": "subitem-1"
                            },
                            {
                              "text": "Subitem 2",
                              "value": "subitem-2"
                            },
                            {
                              "text": "Subitem 3",
                              "value": "subitem-3"
                            }
                          ]
                        }
                      },
                      {
                        "text": "Subitem 3",
                        "expanded": true,
                        "sub": {
                          "items": [
                            {
                              "text": "Subitem 1",
                              "value": "subitem-1"
                            },
                            {
                              "text": "Subitem 2",
                              "value": "subitem-2"
                            },
                            {
                              "text": "Subitem 3",
                              "value": "subitem-3"
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}) }}

Indeterminado

Usando el parámetro "isIndeterminate": true podemos crear un item del checkbox que tenga 3 estados: marcado, desmarcado o indeterminado. El estado indeterminado expresa que hay sólo algún item seleccionado pero no todos. Útil para selecciones múltiples.

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Indeterminado

Contenido

Nunjucks macro

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

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

Selecciona organismo
Mostrar códigodel ejemplo: Con searchbar

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-searchbar",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "searchbar": {
    "id": "with-searchbar-searchbar",
    "label": {
      "text": "Buscar"
    },
    "placeholder": "Buscar organismo"
  },
  "items": [
    {
      "text": "Item 1",
      "id": "with-searchbar-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-searchbar-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-searchbar-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-searchbar-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-searchbar-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-searchbar-item-3"
        }
      }
    }
  ]
}) }}

Selecciona organismo

Error:Error: Introduce al menos un carácter

Mostrar códigodel ejemplo: Con error en searchbar

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-searchbar-error",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "searchbar": {
    "id": "with-searchbar-error-searchbar",
    "label": {
      "text": "Buscar"
    },
    "placeholder": "Buscar organismo",
    "errorMessage": {
      "text": "Error: Introduce al menos un carácter",
      "classes": "mt-xs"
    }
  },
  "items": [
    {
      "text": "Item 1",
      "id": "with-searchbar-error-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-searchbar-error-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-searchbar-error-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-searchbar-error-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-searchbar-error-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-searchbar-error-item-3"
        }
      }
    }
  ]
}) }}

Con searchbar y scroll en el contenedor de árbol

Puedes usar las clases de CSS: max-h-64 o max-h-40 junto a overflow-y-auto, para poner barras de scroll al árbol en caso de que su altura sea muy grande o bien cuando la altura crezca debido a que los items sean expandidos por el usuario.

Selecciona organismo
Mostrar códigodel ejemplo: Con searchbar y scroll en el contenedor de árbol

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-searchbar-scroll",
  "classes": "mt-base max-h-64 overflow-y-auto",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "searchbar": {
    "id": "with-searchbar-scroll-searchbar",
    "label": {
      "text": "Buscar"
    },
    "placeholder": "Buscar organismo"
  },
  "items": [
    {
      "text": "Item 1",
      "id": "with-searchbar-scroll-item-1",
      "expanded": 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-searchbar-scroll-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "with-searchbar-scroll-item-2",
      "expanded": 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-searchbar-scroll-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "with-searchbar-scroll-item-3",
      "expanded": 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-searchbar-scroll-item-3"
        }
      }
    }
  ]
}) }}

Peque

Con clases aplicadas.

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Peque

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-classes-applied",
  "classes": "c-tree--sm mt-sm",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "items": [
    {
      "text": "Opción 1",
      "value": "option-1",
      "classes": "-mt-xs pt-1",
      "label": {
        "classes": "text-sm -mt-1"
      }
    },
    {
      "text": "Opción 2",
      "value": "option-2",
      "classes": "-mt-xs pt-1",
      "label": {
        "classes": "text-sm -mt-1"
      },
      "expanded": true,
      "id": "classes-1",
      "sub": {
        "items": [
          {
            "text": "Item",
            "value": "item",
            "classes": "-mt-xs pt-1",
            "label": {
              "classes": "text-sm -mt-1"
            }
          },
          {
            "text": "Item",
            "value": "item",
            "classes": "-mt-xs pt-1",
            "label": {
              "classes": "text-sm -mt-1"
            },
            "active": true
          },
          {
            "text": "Item",
            "value": "item",
            "classes": "-mt-xs pt-1",
            "label": {
              "classes": "text-sm -mt-1"
            }
          }
        ],
        "attributes": {
          "aria-labelledby": "classes-1"
        }
      }
    },
    {
      "text": "Opción 3",
      "value": "option-3",
      "classes": "-mt-xs pt-1",
      "label": {
        "classes": "text-sm -mt-1"
      }
    },
    {
      "text": "Opción 4",
      "value": "option-4",
      "classes": "-mt-xs pt-1",
      "label": {
        "classes": "text-sm -mt-1"
      }
    },
    {
      "text": "Opción 5",
      "value": "option-5",
      "classes": "-mt-xs pt-1",
      "label": {
        "classes": "text-sm -mt-1"
      }
    }
  ]
}) }}

Con idprefix

Mostrar código para ver el idPrefix aplicado

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con idprefix

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-idprefix",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "tree-menu-item",
  "items": [
    {
      "text": "Opción 1",
      "value": "option-1"
    },
    {
      "text": "Opción 2",
      "value": "option-2"
    },
    {
      "text": "Opción 3",
      "value": "option-3"
    },
    {
      "text": "Opción 4",
      "value": "option-4"
    },
    {
      "text": "Opción 5",
      "value": "option-5"
    }
  ]
}) }}

Con ids individuales

Mostrar código para ver los id aplicados

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con ids individuales

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-individual-ids",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "items": [
    {
      "text": "Opción 1",
      "value": "option-1",
      "id": "option-A"
    },
    {
      "text": "Opción 2",
      "value": "option-2",
      "id": "option-B"
    },
    {
      "text": "Opción 3",
      "value": "option-3",
      "id": "option-C"
    },
    {
      "text": "Opción 4",
      "value": "option-4",
      "id": "option-D"
    },
    {
      "text": "Opción 5",
      "value": "option-5",
      "id": "option-E"
    }
  ]
}) }}

Con atributos

Muestra el código para ver cómo se aplican los atributos

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Con atributos

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-attributes",
  "classes": "mt-base",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "attributes": {
    "id": "tree-id-example"
  },
  "items": [
    {
      "text": "Opción 1",
      "value": "option-1",
      "attributes": {
        "data-attribute-1": "value-A",
        "data-attribute-2": "value-B",
        "data-attribute-3": "value-C"
      }
    },
    {
      "text": "Opción 2",
      "value": "option-2",
      "attributes": {
        "data-attribute-1": "value-A",
        "data-attribute-2": "value-B",
        "data-attribute-3": "value-C"
      }
    },
    {
      "text": "Opción 3",
      "value": "option-3",
      "attributes": {
        "data-attribute-1": "value-A",
        "data-attribute-2": "value-B",
        "data-attribute-3": "value-C"
      },
      "expanded": true,
      "sub": {
        "attributes": {
          "sub-data-attribute-1": "sub-value-A",
          "sub-data-attribute-2": "sub-value-B",
          "sub-data-attribute-3": "sub-value-C"
        },
        "items": [
          {
            "text": "Item",
            "value": "item",
            "attributes": {
              "item-data-attribute-1": "item-value-A",
              "item-data-attribute-2": "item-value-B",
              "item-data-attribute-3": "item-value-C"
            }
          },
          {
            "text": "Item",
            "value": "item"
          },
          {
            "text": "Item",
            "value": "item"
          }
        ]
      }
    },
    {
      "text": "Opción 4",
      "value": "option-4",
      "attributes": {
        "data-attribute-1": "value-A",
        "data-attribute-2": "value-B",
        "data-attribute-3": "value-C"
      }
    },
    {
      "text": "Opción 5",
      "value": "option-5",
      "attributes": {
        "data-attribute-1": "value-A",
        "data-attribute-2": "value-B",
        "data-attribute-3": "value-C"
      }
    }
  ]
}) }}

Mostrar u ocultar un item con javascript

Puedes usar con javascript la función global activateItemsTree(tree, element, show), para mostrar u ocultar todos los items, usando el id del elemento, el parámetro show admite true o false, si le pasamos true se se mostrará el item expandido, y si le pasamos false se mostrará cerrado. Ej: Abre la consola del navegador y escribe activateItemsTree("tree-item-js", "tree-item-js-example-item-1", true) para mostrar todos los items expandidos.

Selecciona organismo
Mostrar códigodel ejemplo: Mostrar u ocultar un item con javascript

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "por defecto",
  "classes": "mt-base",
  "id": "tree-item-js",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "idPrefix": "tree-item-js-example",
  "items": [
    {
      "text": "Item 1",
      "id": "tree-item-js-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": "tree-item-js-example-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "tree-item-js-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": "tree-item-js-example-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "tree-item-js-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": "tree-item-js-example-item-3"
        }
      }
    }
  ]
}) }}

Mostrar u ocultar todos los items con javascript

Puedes usar con javascript la función global activateItemsTree(tree, elements, show), para mostrar u ocultar todos los items, usando los id de los elementos, el parámetro show admite true o false, si le pasamos true se se mostrarán todos los items expandidos, y si le pasamos false se mostrarán cerrados. Ej: Abre la consola del navegador y escribe activateItemsTree("tree-multiple-items-js", ["tree-multiple-items-js-1", "tree-multiple-items-js-2"], true) para mostrar todos los items expandidos.

Selecciona organismo
Mostrar códigodel ejemplo: Mostrar u ocultar todos los items con javascript

Contenido

Nunjucks macro

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

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

Mostrar u ocultar todos los items con javascript con diferentes estados

Puedes usar con javascript la función global activateItemsTree(tree, elements), para mostrar u ocultar todos los items, usando los id de los elementos, el parámetro show admite true o false, si le pasamos true se se mostrarán todos los items expandidos, y si le pasamos false se mostrarán cerrados. Ej: Abre la consola del navegador y escribe activateItemsTree("tree-multiple-items-states-js", [["tree-multiple-items-states-item-1", true], ["tree-multiple-items-states-item-3", false]]) para mostrar todos los items expandidos.

Selecciona organismo
Mostrar códigodel ejemplo: Mostrar u ocultar todos los items con javascript con diferentes estados

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "por defecto",
  "classes": "mt-base",
  "id": "tree-multiple-items-states-js",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "idPrefix": "tree-multiple-items-states-example",
  "items": [
    {
      "text": "Item 1",
      "id": "tree-multiple-items-states-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": "tree-multiple-items-states-item-1"
        }
      }
    },
    {
      "text": "Item 2",
      "id": "tree-multiple-items-states-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": "tree-multiple-items-states-item-2"
        }
      }
    },
    {
      "text": "Item 3",
      "id": "tree-multiple-items-states-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": "tree-multiple-items-states-item-3"
        }
      }
    }
  ]
}) }}

Mostrar u ocultar un item con muchos niveles de profundidad con javascript

Puedes usar con javascript la función global activateItemsTree(tree, element, show), para mostrar u ocultar un item, usando el id del elemento, el parámetro show admite true o false, si le pasamos true se se mostrará el item expandido, y si le pasamos false se mostrará cerrado. Ej: Abre la consola del navegador y escribe activateItemsTree("tree-item-deep-js", "sub-sub-sub-tree-item-nodes-2-2-2-2", true) se abrirá el último elemento del arbol, y el resto de elementos superiores.

Selecciona organismo

Selecciona el organismo al que perteneces.

Mostrar códigodel ejemplo: Mostrar u ocultar un item con muchos niveles de profundidad con javascript

Contenido

Nunjucks macro

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

{{ componentTree({
  "name": "with-many-depth-levels",
  "classes": "mt-base",
  "id": "tree-item-deep-js",
  "fieldset": {
    "legend": {
      "text": "Selecciona organismo"
    }
  },
  "hint": {
    "text": "Selecciona el organismo al que perteneces."
  },
  "idPrefix": "tree-item-nodes",
  "items": [
    {
      "text": "Item 1",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ]
      }
    },
    {
      "text": "Item 2",
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "value": "subitem-1"
          },
          {
            "text": "Subitem 2",
            "value": "subitem-2"
          },
          {
            "text": "Subitem 3",
            "value": "subitem-3"
          }
        ]
      }
    },
    {
      "text": "Item 3",
      "expanded": false,
      "sub": {
        "items": [
          {
            "text": "Subitem 1",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3"
                }
              ]
            }
          },
          {
            "text": "Subitem 2",
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3"
                }
              ]
            }
          },
          {
            "text": "Subitem 3",
            "expanded": true,
            "sub": {
              "items": [
                {
                  "text": "Subitem 1",
                  "value": "subitem-1"
                },
                {
                  "text": "Subitem 2",
                  "value": "subitem-2"
                },
                {
                  "text": "Subitem 3",
                  "value": "subitem-3",
                  "expanded": true,
                  "sub": {
                    "items": [
                      {
                        "text": "Subitem 1",
                        "sub": {
                          "items": [
                            {
                              "text": "Subitem 1",
                              "value": "subitem-1"
                            },
                            {
                              "text": "Subitem 2",
                              "value": "subitem-2"
                            },
                            {
                              "text": "Subitem 3",
                              "value": "subitem-3"
                            }
                          ]
                        }
                      },
                      {
                        "text": "Subitem 2",
                        "sub": {
                          "items": [
                            {
                              "text": "Subitem 1",
                              "value": "subitem-1"
                            },
                            {
                              "text": "Subitem 2",
                              "value": "subitem-2"
                            },
                            {
                              "text": "Subitem 3",
                              "value": "subitem-3"
                            }
                          ]
                        }
                      },
                      {
                        "text": "Subitem 3",
                        "expanded": true,
                        "sub": {
                          "items": [
                            {
                              "text": "Subitem 1",
                              "value": "subitem-1"
                            },
                            {
                              "text": "Subitem 2",
                              "value": "subitem-2"
                            },
                            {
                              "text": "Subitem 3",
                              "value": "subitem-3"
                            }
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    }
  ]
}) }}