Skip to content

Commit 05870c5

Browse files
authored
Adding long press section to MenuTrigger docs (#2811)
1 parent 0e1a078 commit 05870c5

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

packages/@react-spectrum/menu/docs/MenuTrigger.mdx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default Layout;
1313
import docs from 'docs:@react-spectrum/menu';
1414
import {HeaderInfo, PropTable, PageDescription} from '@react-spectrum/docs';
1515
import packageData from '@react-spectrum/menu/package.json';
16+
import {Keyboard} from '@react-spectrum/text';
1617

1718
```jsx import
1819
import {ActionButton} from '@react-spectrum/button'
@@ -42,7 +43,7 @@ keywords: [menu, dropdown, action menu]
4243
```tsx example
4344
<MenuTrigger>
4445
<ActionButton>
45-
Edit
46+
Edit
4647
</ActionButton>
4748
<Menu>
4849
<Item>Cut</Item>
@@ -82,6 +83,43 @@ function Example() {
8283
}
8384
```
8485

86+
## Long press
87+
By default, a MenuTrigger's Menu is opened by pressing the trigger element or activating it via the <Keyboard>Space</Keyboard> or <Keyboard>Enter</Keyboard> keys. However, there may be cases in which your trigger element
88+
should perform a separate default action on press such as selection, and should only display the Menu when long pressed. This behavior can be changed by providing `"longPress"` to the `trigger` prop. With this prop, the Menu will only be opened upon
89+
pressing and holding the trigger element or by using the <Keyboard>Option</Keyboard> (<Keyboard>Alt</Keyboard> on Windows) + <Keyboard>Down Arrow</Keyboard>/<Keyboard>Up Arrow</Keyboard> keys while focusing the trigger element.
90+
91+
The example below illustrates how one would setup a MenuTrigger to have long press behavior.
92+
93+
```tsx example
94+
import CloneStamp from '@spectrum-icons/workflow/CloneStamp';
95+
import Crop from '@spectrum-icons/workflow/Crop';
96+
import CropRotate from '@spectrum-icons/workflow/CropRotate';
97+
import Slice from '@spectrum-icons/workflow/Slice';
98+
import {Text} from '@react-spectrum/text';
99+
100+
<MenuTrigger trigger="longPress">
101+
<ActionButton
102+
aria-label="Crop tool"
103+
onPress={() => alert('Cropping!')}>
104+
<Crop />
105+
</ActionButton>
106+
<Menu>
107+
<Item textValue="Crop Rotate">
108+
<CropRotate />
109+
<Text>Crop Rotate</Text>
110+
</Item>
111+
<Item textValue="Slice">
112+
<Slice />
113+
<Text>Slice</Text>
114+
</Item>
115+
<Item textValue="Clone stamp">
116+
<CloneStamp />
117+
<Text>Clone Stamp</Text>
118+
</Item>
119+
</Menu>
120+
</MenuTrigger>
121+
```
122+
85123
## Props
86124

87125
<PropTable component={docs.exports.MenuTrigger} links={docs.links} />

0 commit comments

Comments
 (0)