Skip to content

Commit 926ca58

Browse files
committed
add base docs
1 parent a0a7d13 commit 926ca58

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

docs/developing/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,4 +202,4 @@ Below are the config options that Ionic uses.
202202
| `toastLeave` | `AnimationBuilder` | Provides a custom leave animation for all `ion-toast`, overriding the default "animation". |
203203
| `toggleOnOffLabels` | `boolean` | Overrides the default `enableOnOffLabels` in all `ion-toggle` components. |
204204
| `experimentalCloseWatcher` | `boolean` | **Experimental:** If `true`, the [CloseWatcher API](https://github.com/WICG/close-watcher) will be used to handle all Escape key and hardware back button presses to dismiss menus and overlays and to navigate. Note that the `hardwareBackButton` config option must also be `true`. |
205-
| `focusManagerPriority` | [`FocusManagerPriority[]`](./managing-focus) | **Experimental:** When defined, Ionic will move focus to the appropriate element after each page transition. This ensures that users relying on assistive technology are informed when a page transition happens. Disabled by default. |
205+
| `focusManagerPriority` | [`FocusManagerPriority[]`](./managing-focus#types) | **Experimental:** When defined, Ionic will move focus to the appropriate element after each page transition. This ensures that users relying on assistive technology are informed when a page transition happens. Disabled by default. |

docs/developing/managing-focus.md

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,35 @@ import TabItem from '@theme/TabItem';
1313
/>
1414
</head>
1515

16+
## Manual Focus Management
17+
1618
Ionic provides a `setFocus` API on components such as [Input](../api/input), [Searchbar](../api/searchbar), and [Textarea](../api/textarea) that allows developers to manually set focus to an element. This API should be used in place of the `autofocus` attribute and called within:
1719

1820
- The `ionViewDidEnter` lifecycle event for routing applications when a page is entered.
1921
- The `didPresent` lifecycle event for overlays when an overlay is presented.
2022
- The `appload` event for vanilla JavaScript applications when the application loads.
2123
- The result of a user gesture or interaction.
2224

23-
## Why not autofocus?
25+
### Why not autofocus?
2426

2527
The `autofocus` attribute is a standard HTML attribute that allows developers to set focus to an element when a page loads. This attribute is commonly used to set focus to the first input element on a page. However, the `autofocus` attribute can cause issues in routing applications when navigating between pages. This is because the `autofocus` attribute will set focus to the element when the page loads, but will not set focus to the element when the page is revisited. Learn more about the `autofocus` attribute in the [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/autofocus).
2628

27-
## Platform Restrictions
29+
### Platform Restrictions
2830

2931
There are platform restrictions you should be aware of when using the `setFocus` API, including:
3032

3133
1. Android requires user interaction before setting focus to an element. This can be as simple as a user tapping on the screen.
3234
2. Interactive elements can only focused a result of a user gesture on Mobile Safari (iOS), such as calling `setFocus` as the result of a button click.
3335

34-
## Basic Usage
36+
### Basic Usage
3537

3638
The example below demonstrates how to use the `setFocus` API to request focus on an input when the user clicks a button.
3739

3840
import Basic from '@site/static/usage/v8/input/set-focus/index.md';
3941

4042
<Basic />
4143

42-
## Routing
44+
### Routing
4345

4446
Developers can use the `ionViewDidEnter` lifecycle event to set focus to an element when a page is entered.
4547

@@ -126,7 +128,7 @@ export default Home;
126128
</Tabs>
127129
````
128130

129-
## Overlays
131+
### Overlays
130132

131133
Developers can use the `didPresent` lifecycle event to set focus to an element when an overlay is presented.
132134

@@ -236,3 +238,44 @@ export default Home;
236238
</TabItem>
237239
</Tabs>
238240
````
241+
242+
## Assistive Technology Focus Management
243+
244+
By default, Single Page Applications have no built-in way of informing screen readers that the active view has changed in a browser or webview. This means that users who rely on assistive technology do not always know if a navigation event occurred.
245+
246+
Developers who enable the [focusManagerPriority config](./config#ionicconfig) can delegate focus management to Ionic during page transitions. When enabled, Ionic will move focus to the correct element as specified in the config option. This will inform screen readers that a navigation event occurred.
247+
248+
### Types
249+
250+
```typescript
251+
type FocusManagerPriority = 'content' | 'heading' | 'banner';
252+
```
253+
254+
### Content Types
255+
256+
The following table explains what each content type represents:
257+
258+
| Type | Description | Ionic Component | Semantic HTML Equivalent | Landmark Equivalent |
259+
| - | - | - | - | - |
260+
| `content` | The main portion of the view. | [Content](../api/content) | [`main`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/main) | [`role="main"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Main_role) |
261+
| `heading` | The title of the view. | [Title](../api/title) | [`h1`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/h1) | [`role="heading"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/heading_role) with [`aria-level="1"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-level) |
262+
| `banner` | The header of the view. | [Header](../api/header) | [`header`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/header) | [`role="banner"`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Banner_Role)|
263+
264+
:::important
265+
TODO
266+
:::
267+
268+
### Specifying Priority
269+
270+
The config should be specified in order is decreasing priority. In the following example, the focus manager will always focus headings. Ionic only proceeds to the next focus priority if a view does not have a previous focus priority. In the following example, Ionic will only focus the banner if a view does not have a heading:
271+
272+
```js
273+
focusManagerPriority: ['heading', 'banner']
274+
```
275+
276+
### Implementation Notes
277+
278+
- When specifying a focus priority, browsers may still move focus within that focus priority. For example, when specifying a `'content'` focus priority, Ionic will move focus to the content. However, the browser may then move focus within that content to the first focusable element such as a button.
279+
- If the focus priority does not match any elements in a view, Ionic will instead focus the view itself to ensure focus generally moves to the correct place. Browsers may then adjust focus within the view.
280+
- When navigating from the current view to the previous view, Ionic will move focus back to the element that presented the current view.
281+
- The focus manager can be overridden on a per-view basis as shown in [Manual Focus Management with Routing](#routing).

0 commit comments

Comments
 (0)