Skip to content

Dropdown

A dropdown component that takes care of all the annoying bits for you, with added support for programmatic triggers on top.

  • Option 1
  • Option 2

You can change the dropdowns position by supplying the align prop.

  • Option 1
  • Option 2
  • Option 1
  • Option 2
  • Option 1
  • Option 2

You can tell the dropdown wrapper to only show the dropdown when it’s children are right-clicked:

  • Option 1
  • Option 2

You can disable a dropdown by passing the disabled prop.

DropdownDisabledExample.astro
<Dropdown disabled {/* ... */}>
<!-- ... -->
</Dropdown>

No, you read that right. You can customize the options too. You can individually disable them, turn them into links and also change their color to any of the default colors:

  • Default
  • Primary
  • Success
  • Warning
  • Danger
  • Disabled
  • As Link

You know how, this entire page, we’ve been assigning our DropdownHelper to a variable? There’s a reason for that. The DropdownHelper allows you to access some built-in functions for programmatically toggling, showing and hiding the dropdown. You can even register a callback for when one of the dropdowns options has been clicked!

Script Tag
import {
class DropdownHelper
DropdownHelper
} from '@studiocms/ui/components';
const
const dropdown: DropdownHelper
dropdown
= new
new DropdownHelper(id: string, fullWidth?: boolean): DropdownHelper

A helper function to interact with dropdowns.

@paramid The ID of the dropdown.

@paramfullWidth Whether the dropdown should be full width. Not needed normally.

DropdownHelper
('dropdown');
const dropdown: DropdownHelper
dropdown
.
DropdownHelper.registerClickCallback: (func: (value: string) => void) => void

Registers a click callback for the dropdown options. Whenever one of the options is clicked, the callback will be called with the value of the option.

@paramfunc The callback function.

registerClickCallback
((
value: string
value
) => {
// `value` will be the value you gave your option in the dropdown wrapper.
any
console
.
any
log
(
value: string
value
);
});
// You can toggle the dropdown like this:
const dropdown: DropdownHelper
dropdown
.
DropdownHelper.toggle: () => void

A function to toggle the dropdown.

toggle
();
// Instead of toggling, you can simply show or hide the dropdown:
const dropdown: DropdownHelper
dropdown
.
DropdownHelper.show: () => void

A function to show the dropdown.

show
();
const dropdown: DropdownHelper
dropdown
.
DropdownHelper.hide: () => void

A function to hide the dropdown.

hide
();