Skip to content

Commit e07cc82

Browse files
Docsite: Fix unfocusable tooltip in Toggle Component Example. (#21680)
1 parent 25540dd commit e07cc82

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

packages/react-examples/src/react/Toggle/Toggle.CustomLabel.Example.tsx

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
import * as React from 'react';
2-
import { Icon } from '@fluentui/react/lib/Icon';
2+
import { DefaultButton } from '@fluentui/react/lib/Button';
33
import { Stack, IStackTokens } from '@fluentui/react/lib/Stack';
44
import { Toggle } from '@fluentui/react/lib/Toggle';
55
import { TooltipHost } from '@fluentui/react/lib/Tooltip';
6+
import { useId } from '@fluentui/react-hooks';
67

78
const stackTokens: IStackTokens = { childrenGap: 10 };
89

10+
const buttonStyles = {
11+
root: {
12+
background: 'transparent',
13+
border: 'none',
14+
minWidth: '16px',
15+
padding: 0,
16+
},
17+
};
18+
919
export const ToggleCustomLabelExample: React.FunctionComponent = () => {
20+
const [showTooltip, setShowTooltip] = React.useState(false);
21+
const tooltipId = useId('tooltipId');
22+
23+
const iconWithTooltip = (
24+
<>
25+
<TooltipHost content={showTooltip ? 'Info tooltip' : undefined} id={tooltipId}>
26+
<DefaultButton
27+
aria-label={'more info'}
28+
aria-describedby={showTooltip ? tooltipId : undefined}
29+
// eslint-disable-next-line react/jsx-no-bind
30+
onClick={() => setShowTooltip(!showTooltip)}
31+
styles={buttonStyles}
32+
iconProps={{ iconName: 'Info' }}
33+
/>
34+
</TooltipHost>
35+
</>
36+
);
37+
1038
return (
1139
<Stack tokens={stackTokens}>
12-
<Toggle
13-
label={
14-
<div>
15-
Custom label{' '}
16-
<TooltipHost content="Info tooltip">
17-
<Icon iconName="Info" aria-label="Info tooltip" />
18-
</TooltipHost>
19-
</div>
20-
}
21-
onText="On"
22-
offText="Off"
23-
onChange={_onChange}
24-
/>
40+
<Toggle label={<div>Custom label {iconWithTooltip}</div>} onText="On" offText="Off" onChange={_onChange} />
2541

2642
<Toggle
27-
label={
28-
<div>
29-
Custom inline label{' '}
30-
<TooltipHost content="Info tooltip">
31-
<Icon iconName="Info" aria-label="Info tooltip" />
32-
</TooltipHost>
33-
</div>
34-
}
43+
label={<div>Custom inline label {iconWithTooltip}</div>}
3544
inlineLabel
3645
onText="On"
3746
offText="Off"

0 commit comments

Comments
 (0)