Skip to content

Commit 1572779

Browse files
authored
Merge pull request #1284 from gitKrystan/tab-options
Ensure types reflect optional-ness of tab options
2 parents a9353db + 379e63f commit 1572779

4 files changed

Lines changed: 25 additions & 17 deletions

File tree

API.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ keyboard.
311311

312312
#### Parameters
313313

314-
* `options` **[Object][72]?** optional tab behaviors
314+
* `options` **[Object][72]?** optional tab behaviors (optional, default `{}`)
315315

316316
* `options.backwards` **[boolean][71]** indicates if the the user navigates backwards (optional, default `false`)
317317
* `options.unRestrainTabIndex` **[boolean][71]** indicates if tabbing should throw an error when tabindex is greater than 0 (optional, default `false`)
@@ -891,7 +891,7 @@ Sets up the basic framework used by application tests.
891891

892892
* `context` **[Object][72]** the context to setup
893893

894-
Returns **[Promise][66]<[Object][72]>** resolves with the context that was setup
894+
Returns **[Promise][66]\<void>** resolves when the context is set up
895895

896896
### validateErrorHandler
897897

@@ -1018,7 +1018,7 @@ Returns deprecations which have occured so far for a the current test context
10181018

10191019
### Parameters
10201020

1021-
* `callback` **CallableFunction?** The callback that when executed will have its DeprecationFailure recorded
1021+
* `callback` **[Function][79]?** The callback that when executed will have its DeprecationFailure recorded
10221022

10231023
### Examples
10241024

@@ -1076,7 +1076,7 @@ Returns warnings which have occured so far for a the current test context
10761076

10771077
### Parameters
10781078

1079-
* `callback` **CallableFunction?** The callback that when executed will have its warnings recorded
1079+
* `callback` **[Function][79]?** The callback that when executed will have its warnings recorded
10801080

10811081
### Examples
10821082

addon-test-support/@ember/test-helpers/dom/tab.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface InertHTMLElement extends HTMLElement {
3131
}
3232

3333
/**
34-
Compiles a list of nodes that can be focused. Walkes the tree, discardes hidden elements and a few edge cases. To calculate the right.
34+
Compiles a list of nodes that can be focused. Walks the tree, discards hidden elements and a few edge cases. To calculate the right.
3535
@private
3636
@param {Element} root the root element to start traversing on
3737
@returns {Array} list of focusable nodes
@@ -43,7 +43,7 @@ function compileFocusAreas(root: Element = document.body) {
4343
throw new Error('Element must be in the DOM');
4444
}
4545

46-
let activeElment = getActiveElement(ownerDocument);
46+
let activeElement = getActiveElement(ownerDocument);
4747
let treeWalker = ownerDocument.createTreeWalker(
4848
root,
4949
NodeFilter.SHOW_ELEMENT,
@@ -76,13 +76,13 @@ function compileFocusAreas(root: Element = document.body) {
7676
}
7777

7878
// Always accept the 'activeElement' of the document, as it might fail the next check, elements with tabindex="-1"
79-
// can be focused programtically, we'll therefor ensure the current active element is in the list.
80-
if (node === activeElment) {
79+
// can be focused programmatically, we'll therefor ensure the current active element is in the list.
80+
if (node === activeElement) {
8181
return NodeFilter.FILTER_ACCEPT;
8282
}
8383

8484
// UA parses the tabindex attribute and applies its default values, If the tabIndex is non negative, the UA can
85-
// foucs it.
85+
// focus it.
8686
return node.tabIndex >= 0
8787
? NodeFilter.FILTER_ACCEPT
8888
: NodeFilter.FILTER_SKIP;
@@ -173,14 +173,12 @@ function findNextResponders(root: Element, activeElement: HTMLElement) {
173173
</caption>
174174
tab({ backwards: true });
175175
*/
176-
export default function triggerTab(options?: {
177-
backwards: boolean;
178-
unRestrainTabIndex: boolean;
179-
}): Promise<void> {
176+
export default function triggerTab({
177+
backwards = false,
178+
unRestrainTabIndex = false,
179+
} = {}): Promise<void> {
180180
return Promise.resolve()
181181
.then(() => {
182-
let backwards = (options && options.backwards) || false;
183-
let unRestrainTabIndex = (options && options.unRestrainTabIndex) || false;
184182
return triggerResponderChange(backwards, unRestrainTabIndex);
185183
})
186184
.then(() => {
@@ -190,7 +188,7 @@ export default function triggerTab(options?: {
190188

191189
/**
192190
@private
193-
@param {boolean} backwards when `true` it selects the previous foucs area
191+
@param {boolean} backwards when `true` it selects the previous focus area
194192
@param {boolean} unRestrainTabIndex when `true`, will not throw an error if tabindex > 0 is encountered
195193
@returns {Promise<void>} resolves when all events are fired
196194
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"prepack": "yarn build",
3030
"postpack": "rimraf addon-test-support/**/*.js public-types",
3131
"clean": "git clean -x -f",
32-
"docs": "documentation build --document-exported \"addon-test-support/@ember/test-helpers/index.js\" --config documentation.yml --markdown-toc-max-depth 3 -f md -o API.md",
32+
"docs": "yarn build && documentation build --document-exported \"addon-test-support/@ember/test-helpers/index.js\" --config documentation.yml --markdown-toc-max-depth 3 -f md -o API.md",
3333
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
3434
"lint:js": "eslint --cache .",
3535
"lint:ts": "tsc --noEmit && tsc --noEmit --project type-tests",

type-tests/api.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import {
6363
DebugInfo as InternalDebugInfo,
6464
DeprecationFailure,
6565
Warning,
66+
tab,
6667
} from '@ember/test-helpers';
6768
import { ComponentInstance } from '@glimmer/interfaces';
6869
import { Owner } from '@ember/test-helpers/build-owner';
@@ -95,6 +96,15 @@ expectTypeOf(select).toEqualTypeOf<
9596
keepPreviouslySelected?: boolean
9697
) => Promise<void>
9798
>();
99+
expectTypeOf(tab).toEqualTypeOf<
100+
({
101+
backwards,
102+
unRestrainTabIndex,
103+
}?: {
104+
backwards?: boolean | undefined;
105+
unRestrainTabIndex?: boolean | undefined;
106+
}) => Promise<void>
107+
>();
98108
expectTypeOf(tap).toEqualTypeOf<
99109
(target: Target, options?: TouchEventInit) => Promise<void>
100110
>();

0 commit comments

Comments
 (0)