-
Notifications
You must be signed in to change notification settings - Fork 204
Description
RFC: Support Host Shortcuts in Apps
Summary
This proposal introduces APIs to support host keyboard shortcuts when pressed within app iframes.
Problem statement
Apps integrated with host run inside their own iframes. Currently, host shortcuts do not function within these iframes.
Example:
"GoToPowerBar"
shortcut in Teams host:
- On Mac browsers:
"option+cmd+e"
- On Windows browsers:
"ctrl+alt+e"
This shortcut should focus the search input box at the top of Teams. If the search box is not visible (e.g., in a narrow window), it should be made visible.
Currently, pressing this shortcut inside an app iframe has no effect.
Additionally, apps may need to override certain host shortcuts. For example, "ctrl+b"
bolds text in the Teams compose box, but if an app has its own compose box, it may want to handle "ctrl+b"
itself.
Detailed Design or Proposal
The design consists of two parts:
- Supporting host shortcuts in apps
- Allowing apps to override certain host shortcuts
Part 1 - Support Host Shortcuts
-
Introduce a new API:
shortcutRelay.enableShortcutRelayCapability
-
When an app calls this API:
-
teams-js
posts a message to request all mapped host shortcuts:callFunctionInHostAndHandleResponse( ApiName.ShortcutRelay_RequestHostShortcuts, // New function in Hub/Hub SDK [], new HostShortcutsResponseHandler(), getApiVersionTag(ApiVersionNumber.V_2, ApiName.App_RequestTeamsShortcut), );
The response from the host will be an object like:
teams-js
stores this response in memory. -
teams-js
attaches a keydown event handler to the app’sdocument
. Using the shortcut map, it checks if the event matches a host shortcut. If so, it forwards the event to host:if (matchingShortcut) { const payload = serializeKeydownEvent(event); callFunctionInHost( ApiName.ShortcutRelay_ForwardShortcutEvent, // New function in Hub/Hub SDK [payload], getApiVersionTag(ApiVersionNumber.V_2, ApiName.ShortcutRelay_ForwardShortcutEvent), ); }
-
[Update Aug. 5th] Allow apps to define zones where shortcuts should not be forwarded to the host:
- teams-js exports the attribute
'data-disable-shortcuts-forwarding'
. Apps can add this attribute to DOM elements. - If the shortcut is pressed within a DOM element that has this attribute, the event will not be forwarded to the host.
- teams-js exports the attribute
-
Part 2 - Allow Certain Host Shortcuts to Be Overridden by Apps
-
Host will define which shortcuts can be overridden to ensure consistent user experience.
-
When receiving request
ShortcutRelay_RequestHostShortcuts
, Host will also send a list of overridable shortcuts:{ "shortcuts": ["ctrl+/", "ctrl+shift+/", "ctrl+b"], "overridableShortcuts": ["ctrl+b"] }
-
Introduce a new API:
shortcutRelay.setOverridableShortcutHandler
. Apps can use this API to specify a handler that returns true when it wants to override the shortcut. The function is of type:(event: KeyboardEvent, data: OverridableShortcutHandlerData) => boolean;
-
hen an overridable shortcut is detected,
teams-js
will call the handler above. If it returns true, the shortcut will not be forwarded to the host.
The Next Step
API for Runtime Shortcut Updates
There is a follow-up plan to introduce an API for runtime shortcut updates.
Since Teams allows users to customize shortcuts during runtime, Teams should notify apps whenever shortcut mappings change.
Open for Discussion
- Imagine an app has its own shortcuts, such as ctrl+1+2, which aren't currently used by Teams. When app developers integrate with Teams, they might choose to use the ctrl+1+2 shortcut since it's available. However, if Teams later introduces this shortcut and makes it non-overridable, it could unexpectedly stop working for those app developers.
Discarded Solution
-
teamsCore.enableTeamsShortcutCapability
was changed toshortcutRelay.enableShortcutRelayCapability
Reason Discarded: the ability to support shortcut is not unique to Teams host. -
enableShortcutRelayCapability
was originally designed to accept an argument to allow apps to override shortcuts:onOverridableShortcut: (shortcut: Shortcut) => boolean;
Reason Discarded: This discarded solution assumes apps’ overridable shortcuts are known right when we register the host shortcuts. We want to provide a way to override them over time, as shortcuts may change depending on the app state.
-
Sending Shortcut ID in Host-App Messages:
There was a consideration to send shortcut IDs or descriptions (e.g., "Bold") in the message between host and app, rather than just the key combinations.
Reason Discarded: A shortcut description or ID does not provide much actionable context to app developers.