Dropdown Component ================== Overview -------- As dropdowns are common in Odoo, we decided to make a generic dropdown component. It contains all the logic you can usually expect a dropdown to behave. Features ^^^^^^^^ * Toggle the list on click * Direct siblings dropdowns: when one is open, toggle others on hover * Close on outside click * Close the list when an item is selected * Emits an event to inform which list item is clicked * Infinite multi-level support * SIY: style it yourself * Configurable hotkey to open/close a dropdown or select a dropdown item * Keyboard navigation (arrows, enter...) API --- Behind the scenes ^^^^^^^^^^^^^^^^^ A ```` component is simply a ``
`` having a ``
Slots ~~~~~ In order to properly use a ```` component, you need to populate two `OWL slots `_\ : .. raw:: html
The default slot
It contains the toggler elements of your dropdown and will take place inside your dropdown <button><span/></button> elements.
The menu slot
It contains the elements of the dropdown menu itself and will take place inside your dropdown <ul/> element.
Although it is not mandatory, you will usually place at least one <DropdownItem/> element in the menu slot.
Manage items selection ~~~~~~~~~~~~~~~~~~~~~~ When a ```` gets selected, it emits a custom ``dropdown-item-selected`` event containing its payload. (see `OWL Business Events `_\ ) If you want to react when a ```` gets selected, you need to define two things: .. raw:: html
The dropdown-item-selected event listener
It will receive the payload of the selected item.
A payload for each <DropdownItem/> element
They are just JS objects you declare the way you want. If a payload is not specified, it defaults to null.
Direct Siblings Dropdowns ^^^^^^^^^^^^^^^^^^^^^^^^^ When many dropdowns share **a single parent in the DOM** , they will automatically notify each other about their state changes. Doing so, **when one sibling dropdown is open** , the others will **automatically open themselves on hover**. Available Properties ^^^^^^^^^^^^^^^^^^^^ ```` props ~~~~~~~~~~~~~~~~~~~~~~~~~ .. list-table:: :header-rows: 1 * - Prop name - Default Value - Value type - Description * - ``startOpen`` - ``false`` - boolean - initial dropdown open state * - ``menuClass`` - / - string - could be used to style the dropdown menu ``
    `` * - ``togglerClass`` - / - string - could be used to style the toggler ``
    • Menu Item 1
    • Menu Item 2
    Step 2: make it react to clicks ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ So in your qweb template you would write something like that: .. code-block:: xml Menu Item And in your JS file, when an item is selected, you would receive the payload back like that: .. code-block:: js itemSelected(event) { const eventDetail = event.detail; const itemPayload = eventDetail.payload; console.log(itemPayload.a === 15); } In this case, if you click on this menu item, the console will print « true ». Step 3: make it shine ^^^^^^^^^^^^^^^^^^^^^ Now that you understand the basics of the Dropdown Component, all you need to do is style it the way you want. ✨ Are you ready to make it shine? ✨ Default CSS classes are: * ``.o_dropdown`` : the whole dropdown * ``.o_dropdown_toggler`` : the dropdown button * ``.o_dropdown_menu`` : the dropdown menu list * ``.o_dropdown_item`` : a dropdown item But you can go even further by extending them: - ```` will become .. code-block:: xml
    ...
    - ```` will become .. code-block:: xml
    ...
    - ```` will become .. code-block:: xml
      ...
    - ```` will become .. code-block:: xml
  • ...
  • You can also make dropdown right aligned by passing 'o_dropdown_menu_right' in menuClass ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * ```` will become .. code-block:: xml
      ...
    More Examples ------------- Direct Siblings Dropdown ^^^^^^^^^^^^^^^^^^^^^^^^ When one dropdown toggler is clicked (\ **File** , **Edit** or **About** ), the others will open themselves on hover. This example uses the dropdown components without added style. .. code-block:: xml
    File Open New Document New Spreadsheet Edit Undo Redo Search About Help Check update
    Multi-level Dropdown ^^^^^^^^^^^^^^^^^^^^ This example uses the dropdown components without added style. Flat version ~~~~~~~~~~~~ .. code-block:: xml File Open Save New Document Spreadsheet Save as... CSV PDF Nested version ~~~~~~~~~~~~~~ .. code-block:: xml File Open New Document Spreadsheet Save Save as... CSV PDF Recursive Multi-level Dropdown ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This example make use of inline style. .. code-block:: xml