|
| 1 | +--- |
| 2 | +title: Focus feature in Adaptive Card Extension |
| 3 | +description: The focus feature allows 3P developers to determine focus of elements in the Quick View. |
| 4 | +ms.date: 03/15/2023 |
| 5 | +--- |
| 6 | +# Focus feature in Adaptive Card Extension |
| 7 | + |
| 8 | +Microsoft added support for the focus feature, unique to Viva Connections, in the [SharePoint Framework (SPFx) v1.17](../../../release-1.17.md) release. |
| 9 | + |
| 10 | +> [!NOTE] |
| 11 | +> This tutorial also assumes that you've already built an SPFx Adaptive Card Extension. |
| 12 | +> |
| 13 | +> To learn how to create your first SPFx Adaptive Card Extension, see [Build your first SharePoint Adaptive Card Extension](../../get-started/build-first-sharepoint-adaptive-card-extension.md). |
| 14 | +
|
| 15 | +## Focus Feature |
| 16 | + |
| 17 | +Just like the way that developers can set a template and data via get data() and get template(), users will be able to hook into a new getter method that will allow them the flexibility to pass in an initial focus element on each render. If there is no implementation provided on the developers end, then a focus on the first tab-able element will be set. |
| 18 | + |
| 19 | +```typescript |
| 20 | +/** |
| 21 | + * An optional focus element to set focus when the view is rendered for accessibility purposes. |
| 22 | + * @remarks If not overriden, the focus element defaulted to the first actionable element of the quick view. |
| 23 | + * |
| 24 | + * @virtual |
| 25 | + */ |
| 26 | + public get focusParameters(): IFocusParameters | undefined { |
| 27 | + return undefined; |
| 28 | + } |
| 29 | +``` |
| 30 | + |
| 31 | +This new function allows developers to customize what the focus element is by returning `IFocusParameters`. The return values are as follows: |
| 32 | + |
| 33 | +- `focusTarget`: Set to the root element of the quick view by default. |
| 34 | +- `ariaLive` [OPTIONAL]: Determines reading priority from a screen reader standpoint. Set to off by default. |
| 35 | + |
| 36 | +```typescript |
| 37 | +{ |
| 38 | + /** |
| 39 | + * Sets the default focus on the DOM. Developers pass in the id of a unique element that is to attain focus within a quick view. |
| 40 | + * If the `focusTarget` is not defined then the root element is selected. |
| 41 | + */ |
| 42 | + focusTarget: string | undefined; |
| 43 | + |
| 44 | + /** |
| 45 | + * Sets the accessibility reading of the contents within the focus target. |
| 46 | + * Polite - Content in the target's subtree is read when the user is idle. |
| 47 | + * Assertive - Disrupts any announcement in favor of the changed contents within the target's subtree. |
| 48 | + * Off - The screen reader will not read contents within the target's subtree. |
| 49 | + */ |
| 50 | + ariaLive?: 'polite' | 'assertive' | 'off'; |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +## Tutorial and Examples |
| 55 | + |
| 56 | +You can take a look at [this tutorial](./FocusFeatureTutorial.md) which goes over a step by step guide on how to create a card with the available media upload action. |
| 57 | + |
| 58 | +1. **Read target information after once user is idle** |
| 59 | + |
| 60 | + In your `focusParameters` function, return the following object: |
| 61 | + |
| 62 | + ```javascript |
| 63 | + { |
| 64 | + focusTarget: myFocusTarget, |
| 65 | + ariaLive: 'polite' |
| 66 | + } |
| 67 | + ``` |
| 68 | + |
| 69 | +1. **Read target information immediately** |
| 70 | + |
| 71 | + In your `focusParameters` function, return the following object: |
| 72 | + |
| 73 | + ```javascript |
| 74 | + { |
| 75 | + focusTarget: myFocusTarget, |
| 76 | + ariaLive: 'assertive' |
| 77 | + } |
| 78 | + ``` |
| 79 | + |
| 80 | +1. **Read all contents of the quick view** |
| 81 | + |
| 82 | + In your template json file, add the following action: |
| 83 | + |
| 84 | + In your `focusParameters` function, return the following object: |
| 85 | + |
| 86 | + ```javascript |
| 87 | + { |
| 88 | + focusTarget: undefined, |
| 89 | + ariaLive: 'assertive' |
| 90 | + } |
| 91 | + ``` |
| 92 | + |
| 93 | +## Availability of focus feature |
| 94 | + |
| 95 | +> [!NOTE] |
| 96 | +> Currently this feature is not supported in teams mobile. |
| 97 | + |
| 98 | + Action | Viva Connection Desktop | Viva Connections Mobile | Browser |
| 99 | +------------- | ----------------------- | ----------------------- | --------- |
| 100 | +Focus Feature | Supported | Not Supported | Supported |
0 commit comments