GrowMenuTrigger
Runs the real component in your browser.
Custom status content shared by a trigger and its menu footer.
Status: experimental · Components: GrowMenuTrigger
Import
Section titled “Import”import { GrowMenuTrigger } from 'nacre'The footer has a 28pt hit area. Its focus indicator sits 6pt inside each side and 4pt from the top and bottom. The text aligns with the menu items.
import { Text, View, signal, windowSize } from 'nsh'import type { ViewRef } from 'nsh'import { GrowMenu, GrowMenuTrigger, Icon, PresenceDot, TEXT_SIZE } from 'nacre'
export function GrowMenuTriggerUsage() { const open = signal(false) const byKeyboard = signal(false) const status = signal<'online' | 'break'>('online') const elapsed = signal('02:15') const online = () => 'Online' const resting = () => 'Break' const currentLabel = () => status() === 'online' ? online() : resting() const anchor = signal({ left: 0, bottom: 0, width: 240 }) let trigger: ViewRef | undefined const label = () => `$Change status · ${currentLabel()}` const body = () => <><PresenceDot kind={status()} label={currentLabel()} /><Text class={`${TEXT_SIZE.small} text-foreground`}>{currentLabel()}</Text><Text class={`${TEXT_SIZE.caption} tabular-nums text-muted-foreground`}>{elapsed()}</Text><Icon name="chevron-down" size={14} color="muted-foreground" /></> return <View> <GrowMenuTrigger testID="status-trigger" inset={14} label={label()} expanded={open()} viewRef={(node) => trigger = node} onPress={(e) => { byKeyboard.set(e.clickCount === 0) trigger?.measure().then((frame) => { if (!frame) return anchor.set({ left: frame.pagePosition.x - 1, bottom: windowSize().height - frame.pagePosition.y - frame.bounds.size.height - 1, width: 240 }) open.set(true) }) }}>{body()}</GrowMenuTrigger> <GrowMenu testID="status-panel" open={open()} onClose={() => open.set(false)} returnFocus={() => trigger} focusFirst={byKeyboard()} left={anchor().left} bottom={anchor().bottom} width={anchor().width} items={[{ label: status() === 'online' ? resting() : online(), presence: status() === 'online' ? 'break' : 'online', onSelect: () => { status.set(status() === 'online' ? 'break' : 'online') elapsed.set('00:00') }, }]} footer={<GrowMenuTrigger footer testID="status-close" label={label()} onPress={() => open.set(false)}>{body()}</GrowMenuTrigger>} /> </View>}Keyboard
Section titled “Keyboard”| Key | Action |
|---|---|
| Tab | Focus the entry |
| Space / Return | Activate |
Accessibility
Section titled “Accessibility”- Required label names the button; focus has a visible indicator.
Do / Don’t
Section titled “Do / Don’t”Do
- Keep the accessible name
- Change color on press without scaling
Don’t
- Nest interactive controls
Property descriptions follow the Chinese source comments.
GrowMenuTrigger
Section titled “GrowMenuTrigger”| Prop | Type | Default | Description |
|---|---|---|---|
label * |
string |
— | |
expanded |
boolean |
— | |
footer |
boolean |
— | 菜单内的收起行,焦点提示左右各内缩 6pt、上下各 4pt。 |
inset |
number |
— | 内容左内缩,触发行默认 4pt,菜单底行默认 14pt。原地展开时可传触发内容的实际偏移。 |
size |
'sm' | 'md' |
— | 28pt 紧凑入口或 36pt 侧栏行。 |
onPress * |
(event: PressEvent) => void |
— | |
viewRef |
(node: ViewRef) => void |
— | |
testID |
string |
— | |
children |
JSX.Element |
— | 自定义状态点、文字、计时和箭头;不额外包 Text |
* required