Skip to content

Feature/tooltip #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ExpandedNodes": [
"",
"\\Icon",
"\\Icon\\Icon"
],
"SelectedNode": "\\Icon\\Icon\\IconComponent.tsx",
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Empty file.
Binary file added .vs/powercat-code-components/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file added .vs/slnx.sqlite
Binary file not shown.
8 changes: 8 additions & 0 deletions Icon/Icon/ContextExtended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This is undocumented - but needed since canvas apps sets non-zero tabindexes
// so we must use the tabindex provided by the context for accessibility purposes
export interface ContextEx {
accessibility: {
assignedTabIndex: number;
assignedTooltip?: string;
};
}
36 changes: 20 additions & 16 deletions Icon/Icon/IconComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IPartialTheme,
mergeStyles,
ThemeProvider,
TooltipHost,
} from '@fluentui/react';
import { useAsync } from '@fluentui/react-hooks';

Expand All @@ -18,6 +19,7 @@ export interface IconComponentProps {
height?: number;
iconName?: string;
text?: string;
tooltipContent?: string;
onSelected: () => void;
disabled?: boolean;
tabIndex?: number;
Expand Down Expand Up @@ -46,7 +48,7 @@ export enum IconRenderType {
}

export const IconComponent = React.memo((props: IconComponentProps) => {
const { text, disabled, onSelected, tabIndex, ariaLabel, setFocus, themeJSON, renderType } = props;
const { text, tooltipContent, disabled, onSelected, tabIndex, ariaLabel, setFocus, themeJSON, renderType } = props;
const theme = React.useMemo(() => {
try {
return themeJSON ? createTheme(JSON.parse(themeJSON) as IPartialTheme) : undefined;
Expand All @@ -71,21 +73,23 @@ export const IconComponent = React.memo((props: IconComponentProps) => {

return (
<ThemeProvider applyTo="none" theme={theme} className={getIconContainerStyle(props)}>
{renderType === IconRenderType.Icon && (
<FontIcon aria-label={props.ariaLabel} className={getIconClass(props)} iconName={props.iconName} />
)}
{renderType !== IconRenderType.Icon && (
<RenderButtonAs
componentRef={componentRef}
styles={getButtonStyles(props)}
iconProps={getIconProps(props)}
ariaLabel={ariaLabel}
disabled={disabled}
text={text}
onClick={onSelected}
tabIndex={tabIndex}
/>
)}
<TooltipHost content={tooltipContent}>
{renderType === IconRenderType.Icon && (
<FontIcon aria-label={props.ariaLabel} className={getIconClass(props)} iconName={props.iconName} />
)}
{renderType !== IconRenderType.Icon && (
<RenderButtonAs
componentRef={componentRef}
styles={getButtonStyles(props)}
iconProps={getIconProps(props)}
ariaLabel={ariaLabel}
disabled={disabled}
text={text}
onClick={onSelected}
tabIndex={tabIndex}
/>
)}
</TooltipHost>
</ThemeProvider>
);
});
Expand Down
2 changes: 2 additions & 0 deletions Icon/Icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Icon implements ComponentFramework.ReactControl<IInputs, IOutputs>
const allocatedWidth = parseInt(context.mode.allocatedWidth as unknown as string);
const allocatedHeight = parseInt(context.mode.allocatedHeight as unknown as string);
const tabIndex = (context as unknown as ContextEx).accessibility?.assignedTabIndex ?? undefined;
const tooltipContent = (context as unknown as ContextEx).accessibility?.assignedTooltip ?? '';
const inputEvent = context.parameters.InputEvent.raw;
const eventChanged = inputEvent && this.inputEvent !== inputEvent;

Expand All @@ -44,6 +45,7 @@ export class Icon implements ComponentFramework.ReactControl<IInputs, IOutputs>
onSelected: this.onSelect,
iconName: defaultIfEmpty(context.parameters.IconName, 'emoji2'),
text: defaultIfEmpty(context.parameters.Text, ''),
tooltipContent: tooltipContent,
justify: TextAlignmentTypes[context.parameters.TextAlignment.raw],
renderType: RenderTypes[context.parameters.IconType.raw],
iconColor: undefinedIfEmpty(context.parameters.IconColor),
Expand Down
4 changes: 4 additions & 0 deletions Icon/Icon/strings/Icon.1033.resx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
<value>Text</value>
<comment/>
</data>
<data name="TooltipContext" xml:space="preserve">
<value>Text</value>
<comment/>
</data>
<data name="TextAlignment" xml:space="preserve">
<value>Text alignment</value>
<comment/>
Expand Down
Loading