<!--
  GENERATED FILE - do not edit by hand.
  Source of truth: src/components/mds-dropdown/ in the magma monorepo (usage/*.md and the
  component's JSDoc). Regenerated on every stencil build (scripts/component-docs.ts).
-->

# mds-dropdown

> `@maggioli-design-system/magma` 2.15.0. Shadow DOM: style it only through the public CSS custom properties and the parts below.

The `<mds-dropdown>` web component is a floating overlay surface of the Magma Design System that anchors arbitrary slotted content next to an external trigger element. It has no built-in trigger of its own: it attaches to a separate caller resolved via `target` and positions, flips and shifts itself around that element.

#### Semantic Behavior

- **Caller binding**: The dropdown does not render a trigger; it resolves its caller from the `target` selector and wires the chosen interaction onto that external element. Changing `target` re-binds the caller.
- **Visibility is the single source of truth**: The `visible` prop drives the whole lifecycle - it positions the floating element, optionally shows the backdrop, and emits the events; setting it back to `false` dismisses it.
- **Outside-click dismissal**: While open, clicking outside both the host and the caller closes the dropdown.
- **Escape to close**: Pressing Escape hides the dropdown, and hands the focus back to the caller when the panel was holding it.
- **Keyboard, when the panel is a `menu`**: the arrows on the caller open the panel and land on the first entry (Up on the last), Enter does the same; inside the panel the arrows walk the entries and wrap at the ends, Home and End go to the first and to the last, Tab closes and lets the focus leave from the caller. A panel that declares another role is left alone: the arrows of a calendar or of a form belong to what the panel holds.
- **Backdrop**: When `backdrop` is set, a backdrop is shown while the dropdown is visible and removed on close.
- **Emitted events**: `mdsDropdownChange` fires on every visibility transition; `mdsDropdownVisible` and `mdsDropdownHide` fire on open and close respectively. Each detail carries the resolved `caller` and the current `visible` state.
- **Default slot is the panel content**: Anything in the default slot (text, HTML, or other components) is the surface shown when the dropdown is triggered.
- **ARIA wiring**: The panel declares itself a `menu` and names the elements the slot receives as its entries (`role="menuitem"`, a role of their own other than `button` being left alone); the caller receives `aria-haspopup`, an `aria-controls` pointing at the panel and an `aria-expanded` that follows `visible`. A panel that is not a list of actions declares its own `role` in the markup and keeps it, its contents then being left alone. A caller that exposes no role of its own - a generic host that keeps its control inside its shadow root, such as `mds-tab-item` - is left unwired, none of those attributes being valid on it.

#### Properties & Visual Configurations

- **`interaction`** decides how the caller opens the panel: `'click'` toggles on caller click (with outside-click and Escape dismissal), `'mouseover'` opens on hover and closes on mouse leave, and `'none'` wires nothing on the caller, so visibility is controlled programmatically through `visible` (an open panel still closes on outside click and Escape).
- **`target`** (required) is the CSS selector of the external element the dropdown attaches to and positions against.

#### Other behavioral props

- **`placement`** sets the side relative to the caller, taken whenever it has room: by default (auto-placement) the panel moves to the opposite side, then to the sides across, only when it does not fit there. **`disableAutoPlacement`** pins it to `placement`, and **`flip`** then allows the fallback to the opposite side only. The panel is shifted to stay inside the viewport with a safe margin by default - **`disableShift`** opts out of this and **`shiftPadding`** tunes the margin.
- **`offset`** controls the gap between the panel and the caller; the pointer toward the caller is shown by default (**`hideArrow`** removes it) and **`arrowPadding`** insets it from the panel edges.
- the panel tracks the caller smoothly as the page scrolls by default (**`disableSmooth`** opts out); **`strategy`** chooses the CSS positioning mode (`'absolute'` vs `'fixed'`) and **`zIndex`** sets the stacking order.

## Read next

- [`examples.md`](examples.md) - correct usage, from the most common case
- [`mistakes.md`](mistakes.md) - the wrong forms, each with the right one
- [Storybook](https://magma-design-system.github.io/magma/storybook/?path=/docs/ui-dropdown--docs) - the live examples, in the published Storybook of `main`
- [`conventions.md`](../../../../agents/conventions.md), [`variants.md`](../../../../agents/variants.md), [`mistakes.md`](../../../../agents/mistakes.md) - the rules shared by every component

## Props

| Prop | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `arrowPadding` | `arrow-padding` | `number` | `24` | Sets the distance between arrow and dropdown margins. |
| `backdrop` | `backdrop` | `boolean \| undefined` | `false` | Specifies if the component has a backdrop background |
| `disableAutoPlacement` | `disable-auto-placement` | `boolean` | `false` | Pins the component to `placement`: without it, the component moves to another side of the caller when `placement` has no room. |
| `disableShift` | `disable-shift` | `boolean` | `false` | If set, the component will not be kept inside the viewport. |
| `disableSmooth` | `disable-smooth` | `boolean` | `false` | If set, the component will not follow the caller smoothly when the page scrolls. |
| `flip` | `flip` | `boolean` | `false` | With `disableAutoPlacement`, moves the component to the opposite side of the caller when `placement` has no room. Auto-placement, the default, already does it. |
| `hideArrow` | `hide-arrow` | `boolean` | `false` | If set, the component will not have an arrow pointing to the caller. |
| `interaction` | `interaction` | `"click" \| "mouseover" \| "none"` | `'click'` | Specifies if the component is triggered from the caller on mouseover or click event |
| `offset` | `offset` | `number` | `24` | Sets distance between the dropdown and the caller. |
| `placement` | `placement` | `"bottom" \| "bottom-end" \| "bottom-start" \| "left" \| "left-end" \| "left-start" \| "right" \| "right-end" \| "right-start" \| "top" \| "top-end" \| "top-start"` | `'bottom'` | Specifies where the component should be placed relative to the caller: the side it takes whenever it has room there. |
| `shiftPadding` | `shift-padding` | `number` | `24` | Sets a safe area distance between the dropdown and the viewport. |
| `strategy` | `strategy` | `"absolute" \| "fixed"` | `'absolute'` | Sets the CSS position strategy of the component. |
| `target` | `target` | `string` | - | **Required**. Specifies the selector of the target element, this attribute is used with `querySelector` method. |
| `visible` | `visible` | `boolean` | `false` | Specifies the visibility of the component. |
| `zIndex` | `z-index` | `number` | - | Specifies the visibility of the component. |

## Events

| Event | Detail | Description |
| --- | --- | --- |
| `mdsDropdownChange` | `MdsDropdownEventDetail` | Emits when a modal is visible or hidden |
| `mdsDropdownHide` | `MdsDropdownEventDetail` | Emits when a modal is hidden |
| `mdsDropdownVisible` | `MdsDropdownEventDetail` | Emits when a modal is visible |

## Slots

| Slot | Description |
| --- | --- |
| (default) | Add `text string`, `HTML elements` or `components` to this slot, elements will be shown when the component is triggered. |

## CSS custom properties

| Property | Description |
| --- | --- |
| `--mds-dropdown-backdrop-z-index` | Sets the z-index of the backdrop shown with the `backdrop` attribute, the one of the page backdrop by default. |
| `--mds-dropdown-background` | Sets the background-color of the dropdown. |
| `--mds-dropdown-mouseover-delay` | Sets the delay duration of the component when the caller trigger mouseover event, it's used by the javascript code. |
| `--mds-dropdown-z-index` | Sets the z-index of the component. |

Only these are public. Its other 8 are internal: they may change in any release, do not set them.

## Dependencies

Used by: `mds-button-dropdown`, `mds-input-date`, `mds-input-date-range`, `mds-policy-ai`, `mds-pref-language`, `mds-pref-theme`.
