Skip to content
ui8kit

component / components

Dropdown Item

Dropdown Item component

Install

npx ui8kit add dropdown-item

Pulls in: button-plain, compose, inline, kit-button, kit-text, utils

Preview

No static preview for this item: it needs content or a parent that this page cannot supply. The code is below.

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add dropdown-item
components/dropdown-item.svelte
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex
  -1: the menu moves focus with the arrow keys.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type DropdownItemProps = {
    selected?: boolean;
    class?: string;
    children?: Snippet;
    icon?: Snippet;
    right?: Snippet;
    onclick?: () => void;
  };
</script>

<script lang="ts">
  import ButtonPlain from "../compose/ButtonPlain.svelte";
  import Inline from "../compose/Inline.svelte";
  import { cn } from "../utils";

  let { selected = false, class: className, children, icon, right, onclick }: DropdownItemProps = $props();
</script>

<ButtonPlain
  type="button"
  role="menuitem"
  class={cn("group flex h-9 w-full items-center px-2 text-left text-foreground", className)}
  tabindex={-1}
  data-slot="dropdown-item"
  data-state={(selected ? "selected" : "default")}
  onclick={() => onclick?.()}
>
  <Inline
    class={"flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted " +
      "group-data-[state=selected]:bg-muted"}
    data-slot="dropdown-item-content"
  >
    {#if icon}
      <Inline class="flex w-7 shrink-0 items-center pr-2" data-slot="dropdown-item-icon">
        {@render icon?.()}
      </Inline>
    {/if}
    <Inline class={cn("text-xs", "min-w-0 flex-1 truncate px-1 font-bold")} data-slot="dropdown-item-label">
      {@render children?.()}
    </Inline>
    {#if right}
      <Inline class="flex shrink-0 items-center pr-1" data-slot="dropdown-item-right">
        {@render right?.()}
      </Inline>
    {/if}
  </Inline>
</ButtonPlain>

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add dropdown-item
components/dropdown-item.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex
 * -1: the menu moves focus with the arrow keys.
 */
import { type ReactNode } from "react";
import { ButtonPlain, Inline } from "../compose";
import { cn } from "../utils";

export type DropdownItemProps = {
  selected?: boolean;
  className?: string;
  children?: ReactNode;
  icon?: ReactNode;
  right?: ReactNode;
  onClick?: () => void;
};

export function DropdownItem({
  selected = false,
  className,
  children,
  icon,
  right,
  onClick,
}: DropdownItemProps) {
  return (
    <ButtonPlain
      type="button"
      role="menuitem"
      className={cn("group flex h-9 w-full items-center px-2 text-left text-foreground", className)}
      tabIndex={-1}
      data-slot="dropdown-item"
      data-state={(selected ? "selected" : "default")}
      onClick={() => onClick?.()}
    >
      <Inline
        className={"flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted " +
          "group-data-[state=selected]:bg-muted"}
        data-slot="dropdown-item-content"
      >
        {icon ? (
          <Inline className="flex w-7 shrink-0 items-center pr-2" data-slot="dropdown-item-icon">
            {icon}
          </Inline>
        ) : null}
        <Inline className={cn("text-xs", "min-w-0 flex-1 truncate px-1 font-bold")} data-slot="dropdown-item-label">
          {children}
        </Inline>
        {right ? (
          <Inline className="flex shrink-0 items-center pr-1" data-slot="dropdown-item-right">
            {right}
          </Inline>
        ) : null}
      </Inline>
    </ButtonPlain>
  );
}

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add dropdown-item
components/dropdown-item.vue
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex
  -1: the menu moves focus with the arrow keys.
-->
<script lang="ts">
export type DropdownItemProps = {
  selected?: boolean;
  class?: string;
};
</script>

<script setup lang="ts">
import ButtonPlain from "../compose/ButtonPlain.vue";
import Inline from "../compose/Inline.vue";
import { cn } from "../utils";

const { selected = false, class: className } = defineProps<DropdownItemProps>();
const emit = defineEmits<{ click: [] }>();
defineSlots<{ default?(): unknown, icon?(): unknown, right?(): unknown }>();
</script>

<template>
  <ButtonPlain
    type="button"
    role="menuitem"
    :class="cn('group flex h-9 w-full items-center px-2 text-left text-foreground', className)"
    :tabindex="-1"
    data-slot="dropdown-item"
    :data-state="(selected ? 'selected' : 'default')"
    @click="() => emit('click')"
  >
    <Inline
      :class="'flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted ' +
        'group-data-[state=selected]:bg-muted'"
      data-slot="dropdown-item-content"
    >
      <Inline v-if="$slots.icon" class="flex w-7 shrink-0 items-center pr-2" data-slot="dropdown-item-icon">
        <slot name="icon" />
      </Inline>
      <Inline :class="cn('text-xs', 'min-w-0 flex-1 truncate px-1 font-bold')" data-slot="dropdown-item-label">
        <slot />
      </Inline>
      <Inline v-if="$slots.right" class="flex shrink-0 items-center pr-1" data-slot="dropdown-item-right">
        <slot name="right" />
      </Inline>
    </Inline>
  </ButtonPlain>
</template>

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add dropdown-item
components/dropdown-item.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex
 * -1: the menu moves focus with the arrow keys.
 */
import { type JSX } from "solid-js";
import { ButtonPlain, Inline } from "../compose";
import { cn } from "../utils";

export type DropdownItemProps = {
  selected?: boolean;
  class?: string;
  children?: JSX.Element;
  icon?: JSX.Element;
  right?: JSX.Element;
  onClick?: () => void;
};

export function DropdownItem({
  selected = false,
  class: className,
  children,
  icon,
  right,
  onClick,
}: DropdownItemProps) {
  return (
    <ButtonPlain
      type="button"
      role="menuitem"
      class={cn("group flex h-9 w-full items-center px-2 text-left text-foreground", className)}
      tabindex={-1}
      data-slot="dropdown-item"
      data-state={(selected ? "selected" : "default")}
      onClick={() => onClick?.()}
    >
      <Inline
        class={"flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted " +
          "group-data-[state=selected]:bg-muted"}
        data-slot="dropdown-item-content"
      >
        {icon ? (
          <Inline class="flex w-7 shrink-0 items-center pr-2" data-slot="dropdown-item-icon">
            {icon}
          </Inline>
        ) : null}
        <Inline class={cn("text-xs", "min-w-0 flex-1 truncate px-1 font-bold")} data-slot="dropdown-item-label">
          {children}
        </Inline>
        {right ? (
          <Inline class="flex shrink-0 items-center pr-1" data-slot="dropdown-item-right">
            {right}
          </Inline>
        ) : null}
      </Inline>
    </ButtonPlain>
  );
}

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add dropdown-item
blocks/dropdown-item.templ
// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/patterns/dropdown-item.json

package blocks

import (
	"github.com/ui8kit/codegen/generated/templ/ui/button"
	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/text"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// DropdownItemProps are the props of DropdownItem; the values are the JSON shapes of the TypeScript props.
type DropdownItemProps struct {
	Selected any `json:"selected"`
	Class string `json:"className"`
	Icon templ.Component `json:"-"`
	Right templ.Component `json:"-"`
}

// A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex -1: the menu moves focus with the arrow keys.
templ DropdownItem(p DropdownItemProps) {
	{{ vSelected := uiutils.Def(p.Selected, false) }}
	@compose.ButtonPlain(compose.ButtonPlainProps{ButtonProps: button.ButtonProps{Type: "button", Class: uiutils.S(uiutils.Cnv("group flex h-9 w-full items-center px-2 text-left text-foreground", p.Class)), Attrs: uiutils.Attrs("role", "menuitem", "tabindex", float64(-1), "data-slot", "dropdown-item", "data-state", uiutils.Cond(uiutils.T(vSelected), "selected", "default"))}}) {
		@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted group-data-[state=selected]:bg-muted", Attrs: uiutils.Attrs("data-slot", "dropdown-item-content")}}) {
			if uiutils.T((p.Icon != nil)) {
				@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex w-7 shrink-0 items-center pr-2", Attrs: uiutils.Attrs("data-slot", "dropdown-item-icon")}}) {
					if p.Icon != nil {
						@p.Icon
					}
				}
			}
			@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: uiutils.S(uiutils.Cnv("text-xs", "min-w-0 flex-1 truncate px-1 font-bold")), Attrs: uiutils.Attrs("data-slot", "dropdown-item-label")}}) {
				{ children... }
			}
			if uiutils.T((p.Right != nil)) {
				@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex shrink-0 items-center pr-1", Attrs: uiutils.Attrs("data-slot", "dropdown-item-right")}}) {
					if p.Right != nil {
						@p.Right
					}
				}
			}
		}
	}
}

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add dropdown-item
blocks/dropdown-item.html.twig
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/patterns/dropdown-item.json
    A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex -1: the menu moves focus with the arrow keys.
    Props (p): selected, className, icon (slot), right (slot); children: markup. -#}
{%- set v_selected = (p.selected ?? false) -%}
{%- set c_5 -%}
  {%- set c_4 -%}
    {%- if og_t(((p.icon ?? null) is not null)) %}
      {%- set c_1 -%}
        {{ og_slot((p.icon ?? null))|raw }}
      {%- endset -%}
      {{ include('compose/Inline.html.twig', {'class': 'flex w-7 shrink-0 items-center pr-2', 'attrs': og_attrs(['data-slot', 'dropdown-item-icon']), 'children': c_1}, with_context = false) }}
    {%- endif %}
    {%- set c_2 -%}
      {{ og_slot((children ?? null))|raw }}
    {%- endset -%}
    {{ include('compose/Inline.html.twig', {'class': og_s(og_cnv(['text-xs', 'min-w-0 flex-1 truncate px-1 font-bold'])), 'attrs': og_attrs(['data-slot', 'dropdown-item-label']), 'children': c_2}, with_context = false) }}
    {%- if og_t(((p.right ?? null) is not null)) %}
      {%- set c_3 -%}
        {{ og_slot((p.right ?? null))|raw }}
      {%- endset -%}
      {{ include('compose/Inline.html.twig', {'class': 'flex shrink-0 items-center pr-1', 'attrs': og_attrs(['data-slot', 'dropdown-item-right']), 'children': c_3}, with_context = false) }}
    {%- endif %}
  {%- endset -%}
  {{ include('compose/Inline.html.twig', {'class': 'flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted group-data-[state=selected]:bg-muted', 'attrs': og_attrs(['data-slot', 'dropdown-item-content']), 'children': c_4}, with_context = false) }}
{%- endset -%}
{{ include('compose/ButtonPlain.html.twig', {'type': 'button', 'class': og_s(og_cnv(['group flex h-9 w-full items-center px-2 text-left text-foreground', (p.className ?? '')])), 'attrs': og_attrs(['role', 'menuitem', 'tabindex', -1, 'data-slot', 'dropdown-item', 'data-state', (og_t(v_selected) ? 'selected' : 'default')]), 'children': c_5}, with_context = false) }}

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add dropdown-item
blocks/dropdown-item.latte
{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/patterns/dropdown-item.json
    A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex -1: the menu moves focus with the arrow keys.
    Props (p): selected, className, icon (slot), right (slot); children: markup. *}
{var $v_selected = ($p['selected'] ?? false)}
{capture $c_5}
  {capture $c_4}
    {if og_t(((($p['icon'] ?? null) !== null)))}
      {capture $c_1}
        {=og_slot(($p['icon'] ?? null))|noescape}
      {/capture}
      {=og_include('compose/Inline.latte', ['class' => 'flex w-7 shrink-0 items-center pr-2', 'attrs' => og_attrs(['data-slot', 'dropdown-item-icon']), 'children' => (string) $c_1])|noescape}
    {/if}
    {capture $c_2}
      {=og_slot(($children ?? null))|noescape}
    {/capture}
    {=og_include('compose/Inline.latte', ['class' => og_s(og_cnv(['text-xs', 'min-w-0 flex-1 truncate px-1 font-bold'])), 'attrs' => og_attrs(['data-slot', 'dropdown-item-label']), 'children' => (string) $c_2])|noescape}
    {if og_t(((($p['right'] ?? null) !== null)))}
      {capture $c_3}
        {=og_slot(($p['right'] ?? null))|noescape}
      {/capture}
      {=og_include('compose/Inline.latte', ['class' => 'flex shrink-0 items-center pr-1', 'attrs' => og_attrs(['data-slot', 'dropdown-item-right']), 'children' => (string) $c_3])|noescape}
    {/if}
  {/capture}
  {=og_include('compose/Inline.latte', ['class' => 'flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted group-data-[state=selected]:bg-muted', 'attrs' => og_attrs(['data-slot', 'dropdown-item-content']), 'children' => (string) $c_4])|noescape}
{/capture}
{=og_include('compose/ButtonPlain.latte', ['type' => 'button', 'class' => og_s(og_cnv(['group flex h-9 w-full items-center px-2 text-left text-foreground', ($p['className'] ?? '')])), 'attrs' => og_attrs(['role', 'menuitem', 'tabindex', -1, 'data-slot', 'dropdown-item', 'data-state', (og_t($v_selected) ? 'selected' : 'default')]), 'children' => (string) $c_5])|noescape}

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add dropdown-item
blocks/dropdown-item.html.j2
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/patterns/dropdown-item.json
    A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex -1: the menu moves focus with the arrow keys.
    Props (p): selected, className, icon (slot), right (slot); children: markup. -#}
{%- set v_selected = og_def(p['selected'], false) -%}
{%- set c_5 -%}
  {%- set c_4 -%}
    {%- if og_t((og_def(p['icon'], none) is not none)) %}
      {%- set c_1 -%}
        {{ og_slot(og_def(p['icon'], none))|safe }}
      {%- endset -%}
      {{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex w-7 shrink-0 items-center pr-2', 'Attrs': og_attrs(['data-slot', 'dropdown-item-icon'])}, 'children': c_1}) }}
    {%- endif %}
    {%- set c_2 -%}
      {{ og_slot(og_def(children, none))|safe }}
    {%- endset -%}
    {{ og_include('compose/inline.html.j2', {'p': {'Class': og_s(og_cnv(['text-xs', 'min-w-0 flex-1 truncate px-1 font-bold'])), 'Attrs': og_attrs(['data-slot', 'dropdown-item-label'])}, 'children': c_2}) }}
    {%- if og_t((og_def(p['right'], none) is not none)) %}
      {%- set c_3 -%}
        {{ og_slot(og_def(p['right'], none))|safe }}
      {%- endset -%}
      {{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex shrink-0 items-center pr-1', 'Attrs': og_attrs(['data-slot', 'dropdown-item-right'])}, 'children': c_3}) }}
    {%- endif %}
  {%- endset -%}
  {{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex h-7 min-w-0 flex-1 items-center rounded p-1 group-hover:bg-muted group-focus-visible:bg-muted group-data-[state=selected]:bg-muted', 'Attrs': og_attrs(['data-slot', 'dropdown-item-content'])}, 'children': c_4}) }}
{%- endset -%}
{{ og_include('compose/button-plain.html.j2', {'p': {'Type': 'button', 'Class': og_s(og_cnv(['group flex h-9 w-full items-center px-2 text-left text-foreground', og_def(p['className'], '')])), 'Attrs': og_attrs(['role', 'menuitem', 'tabindex', -1, 'data-slot', 'dropdown-item', 'data-state', ('selected' if og_t(v_selected) else 'default')])}, 'children': c_5}) }}

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

A menu item: an optional icon, the label and an optional trailing mark (a check for selected items). tabindex -1: the menu moves focus with the arrow keys.

Props of DropdownItem
PropTypeDefault Description
selected booleanfalsethe chosen item