Skip to content

Commit 30f1728

Browse files
ktaborsMichael JordanreidbarberLFDanLusnowystinger
authored
Adding Unavailable Menu Item docs (#4763)
* Adding Unavailable Menu Item docs * removing similar text * rewording two concepts * fix spelling mistakes Co-authored-by: Michael Jordan <[email protected]> * Adding more explanation in a couple cases * using the Unavailable Items as the name * switching the order of two paragraphs * update docs and types * fix props table * update types and docs table * address review comments --------- Co-authored-by: Michael Jordan <[email protected]> Co-authored-by: Reid Barber <[email protected]> Co-authored-by: Daniel Lu <[email protected]> Co-authored-by: Robert Snow <[email protected]>
1 parent ea35ed0 commit 30f1728

File tree

2 files changed

+75
-5
lines changed

2 files changed

+75
-5
lines changed

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

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ governing permissions and limitations under the License. */}
1010
import {Layout} from '@react-spectrum/docs';
1111
export default Layout;
1212

13+
import contextualHelpTriggerTypes from 'docs:@react-spectrum/menu/src/ContextualHelpTrigger.tsx';
1314
import docs from 'docs:@react-spectrum/menu';
14-
import {HeaderInfo, PropTable, PageDescription} from '@react-spectrum/docs';
15+
import {HeaderInfo, PropTable, PageDescription, VersionBadge} from '@react-spectrum/docs';
1516
import packageData from '@react-spectrum/menu/package.json';
1617
import {Keyboard} from '@react-spectrum/text';
1718

@@ -33,7 +34,7 @@ keywords: [menu, dropdown, action menu]
3334

3435
<HeaderInfo
3536
packageData={packageData}
36-
componentNames={['MenuTrigger', 'Menu']}
37+
componentNames={['MenuTrigger', 'Menu', 'ContextualHelpTrigger']}
3738
sourceData={[
3839
{type: 'Spectrum', url: 'https://spectrum.adobe.com/page/popover/'}
3940
]}
@@ -121,10 +122,74 @@ import {Text} from '@react-spectrum/text';
121122
</MenuTrigger>
122123
```
123124

125+
## Unavailable Items <VersionBadge version="alpha" style={{marginLeft: 4, verticalAlign: 'bottom'}} />
126+
127+
ContextualHelpTrigger disables a menu item's action and replaces it with a popover with information on why the item is unavailable and may link users to more information elsewhere.
128+
129+
The ContextualHelpTrigger accepts exactly
130+
two children: the Item which triggers opening of the Dialog and the Dialog itself. The trigger must be
131+
the first child passed into the ContextualHelpTrigger and should be an Item. Similar to
132+
ContextualHelp, the layout of the Dialog is very deliberate. See [ContextualHelp](ContextualHelp.html#content) for further explanation.
133+
134+
By default, a ContextualHelpTrigger's Dialog is opened by hovering, pressing the trigger element or activating
135+
it via the <Keyboard>Space</Keyboard>, <Keyboard>Enter</Keyboard>, or <Keyboard>Right Arrow</Keyboard> keys.
136+
Hovering another item or pressing the <Keyboard>Esc</Keyboard> key will close the Dialog and leave the Menu open.
137+
138+
Setting the `isUnavailable` prop on the ContextualHelpTrigger makes a Menu Item unavailable and enables the Dialog with contextual help, allowing for programmatic control.
139+
140+
Note that the Menu's `onAction` and `onSelectionChange`
141+
callbacks will not fire for items made unavailable by a ContextualHelpTrigger.
142+
143+
The example below illustrates how one would setup a MenuTrigger to use ContextualHelpTrigger.
144+
145+
```tsx example
146+
import {ContextualHelpTrigger} from '@react-spectrum/menu';
147+
import {Dialog} from '@react-spectrum/dialog';
148+
import {Heading} from '@react-spectrum/text';
149+
import {Content} from '@react-spectrum/view';
150+
151+
<MenuTrigger>
152+
<ActionButton>Edit</ActionButton>
153+
<Menu>
154+
<Item key="undo">Undo</Item>
155+
<Item key="redo">Redo</Item>
156+
<ContextualHelpTrigger isUnavailable>
157+
<Item key="cut">Cut</Item>
158+
<Dialog>
159+
<Heading>Cut</Heading>
160+
<Content>Please select text for 'Cut' to be enabled.</Content>
161+
</Dialog>
162+
</ContextualHelpTrigger>
163+
<ContextualHelpTrigger isUnavailable>
164+
<Item key="copy">Copy</Item>
165+
<Dialog>
166+
<Heading>Copy</Heading>
167+
<Content>Please select text for 'Copy' to be enabled.</Content>
168+
</Dialog>
169+
</ContextualHelpTrigger>
170+
<ContextualHelpTrigger>
171+
<Item key="paste">Paste</Item>
172+
<Dialog>
173+
<Heading>Paste</Heading>
174+
<Content>You have nothing to 'Paste'.</Content>
175+
</Dialog>
176+
</ContextualHelpTrigger>
177+
</Menu>
178+
</MenuTrigger>
179+
```
180+
124181
## Props
125182

183+
### MenuTrigger props
126184
<PropTable component={docs.exports.MenuTrigger} links={docs.links} />
127185

186+
### ContextualHelpTrigger Props
187+
<PropTable component={{
188+
props: {
189+
properties: Object.fromEntries(Object.entries(docs.exports.SpectrumMenuDialogTriggerProps.properties))
190+
}
191+
}} links={contextualHelpTriggerTypes.links} />
192+
128193
## Visual options
129194

130195
### Align and direction

packages/@react-spectrum/menu/src/ContextualHelpTrigger.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ import {Modal, Popover} from '@react-spectrum/overlays';
1919
import React, {Key, ReactElement, useRef} from 'react';
2020
import {useOverlayTriggerState} from '@react-stately/overlays';
2121

22-
export interface SpectrumMenuDialogTriggerProps<T> extends ItemProps<T> {
22+
interface MenuDialogTriggerProps<T> extends ItemProps<T> {
23+
/** Whether the menu item is currently unavailable. */
2324
isUnavailable?: boolean,
25+
/** The triggering Item and the Dialog, respectively. */
26+
children: [ReactElement, ReactElement],
2427
targetKey: Key
2528
}
2629

27-
function ContextualHelpTrigger<T>(props: SpectrumMenuDialogTriggerProps<T>): ReactElement {
30+
export interface SpectrumMenuDialogTriggerProps<T> extends Omit<MenuDialogTriggerProps<T>, 'targetKey' | 'title' | 'textValue' | 'childItems' | 'hasChildItems'> {}
31+
32+
function ContextualHelpTrigger<T>(props: MenuDialogTriggerProps<T>): ReactElement {
2833
let {isUnavailable} = props;
2934

3035
let triggerRef = useRef<HTMLLIElement>(null);
@@ -114,5 +119,5 @@ ContextualHelpTrigger.getCollectionNode = function* getCollectionNode<T>(props:
114119
};
115120
};
116121

117-
let _Item = ContextualHelpTrigger as <T>(props: ItemProps<T> & {isUnavailable?: boolean}) => JSX.Element;
122+
let _Item = ContextualHelpTrigger as <T>(props: SpectrumMenuDialogTriggerProps<T>) => JSX.Element;
118123
export {_Item as ContextualHelpTrigger};

0 commit comments

Comments
 (0)