Skip to content

Commit b4fe5a0

Browse files
authored
ContextualHelp: Update type descriptions and forwardRef (#2836)
* add ref and update export * add JSDoc to types * add description to placement prop
1 parent 2815eea commit b4fe5a0

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

packages/@react-spectrum/contextualhelp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@react-spectrum/dialog": "^3.3.4",
3939
"@react-spectrum/utils": "^3.6.2",
4040
"@react-types/contextualhelp": "3.0.0-alpha.1",
41+
"@react-types/shared": "^3.10.1",
4142
"@spectrum-icons/workflow": "^3.2.1"
4243
},
4344
"devDependencies": {

packages/@react-spectrum/contextualhelp/src/ContextualHelp.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import {ActionButton} from '@react-spectrum/button';
1414
import {Dialog, DialogTrigger} from '@react-spectrum/dialog';
15+
import {FocusableRef} from '@react-types/shared';
1516
import HelpOutline from '@spectrum-icons/workflow/HelpOutline';
1617
import helpStyles from './contextualhelp.css';
1718
import InfoOutline from '@spectrum-icons/workflow/InfoOutline';
@@ -22,12 +23,13 @@ import {SlotProvider} from '@react-spectrum/utils';
2223
import {SpectrumContextualHelpProps} from '@react-types/contextualhelp';
2324
import {useMessageFormatter} from '@react-aria/i18n';
2425

25-
function ContextualHelp(props: SpectrumContextualHelpProps) {
26+
function ContextualHelp(props: SpectrumContextualHelpProps, ref: FocusableRef<HTMLButtonElement>) {
2627
let {
2728
variant = 'help',
2829
placement = 'bottom start',
2930
children,
30-
...otherProps} = props;
31+
...otherProps
32+
} = props;
3133

3234
let formatMessage = useMessageFormatter(intlMessages);
3335

@@ -41,6 +43,7 @@ function ContextualHelp(props: SpectrumContextualHelpProps) {
4143
return (
4244
<DialogTrigger type="popover" placement={placement} hideArrow {...otherProps}>
4345
<ActionButton
46+
ref={ref}
4447
UNSAFE_className={helpStyles['react-spectrum-ContextualHelp-button']}
4548
isQuiet
4649
aria-label={formatMessage('open')}>
@@ -51,12 +54,12 @@ function ContextualHelp(props: SpectrumContextualHelpProps) {
5154
{children}
5255
</Dialog>
5356
</SlotProvider>
54-
5557
</DialogTrigger>
5658
);
5759
}
5860

5961
/**
6062
* Contextual help shows a user extra information about the state of an adjacent component, or a total view.
6163
*/
62-
export {ContextualHelp};
64+
let _ContextualHelp = React.forwardRef(ContextualHelp);
65+
export {_ContextualHelp as ContextualHelp};

packages/@react-types/contextualhelp/src/index.d.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {OverlayTriggerProps, PositionProps} from '@react-types/overlays';
13+
import {OverlayTriggerProps, Placement, PositionProps} from '@react-types/overlays';
1414
import {ReactNode} from 'react';
1515

1616
export interface SpectrumContextualHelpProps extends OverlayTriggerProps, PositionProps {
17-
/** Contents of the Contextual Help popover. */
17+
/**
18+
* Contents of the Contextual Help popover.
19+
*/
1820
children: ReactNode,
19-
/** Indicates whether contents are informative or provides helpful guidance. */
20-
variant?: 'help' | 'info'
21+
/**
22+
* Indicates whether contents are informative or provides helpful guidance.
23+
* @default 'help'
24+
*/
25+
variant?: 'help' | 'info',
26+
/**
27+
* The placement of the popover with respect to the action button.
28+
* @default 'bottom start'
29+
*/
30+
placement?: Placement
2131
}

0 commit comments

Comments
 (0)