Skip to content

Commit

Permalink
Merge pull request #1284 from gitKrystan/tab-options
Browse files Browse the repository at this point in the history
Ensure types reflect optional-ness of tab options
  • Loading branch information
chriskrycho authored Dec 15, 2022
2 parents a9353db + 379e63f commit 1572779
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
8 changes: 4 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ keyboard.

#### Parameters

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

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

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

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

### validateErrorHandler

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

### Parameters

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

### Examples

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

### Parameters

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

### Examples

Expand Down
22 changes: 10 additions & 12 deletions addon-test-support/@ember/test-helpers/dom/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface InertHTMLElement extends HTMLElement {
}

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

let activeElment = getActiveElement(ownerDocument);
let activeElement = getActiveElement(ownerDocument);
let treeWalker = ownerDocument.createTreeWalker(
root,
NodeFilter.SHOW_ELEMENT,
Expand Down Expand Up @@ -76,13 +76,13 @@ function compileFocusAreas(root: Element = document.body) {
}

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

// UA parses the tabindex attribute and applies its default values, If the tabIndex is non negative, the UA can
// foucs it.
// focus it.
return node.tabIndex >= 0
? NodeFilter.FILTER_ACCEPT
: NodeFilter.FILTER_SKIP;
Expand Down Expand Up @@ -173,14 +173,12 @@ function findNextResponders(root: Element, activeElement: HTMLElement) {
</caption>
tab({ backwards: true });
*/
export default function triggerTab(options?: {
backwards: boolean;
unRestrainTabIndex: boolean;
}): Promise<void> {
export default function triggerTab({
backwards = false,
unRestrainTabIndex = false,
} = {}): Promise<void> {
return Promise.resolve()
.then(() => {
let backwards = (options && options.backwards) || false;
let unRestrainTabIndex = (options && options.unRestrainTabIndex) || false;
return triggerResponderChange(backwards, unRestrainTabIndex);
})
.then(() => {
Expand All @@ -190,7 +188,7 @@ export default function triggerTab(options?: {

/**
@private
@param {boolean} backwards when `true` it selects the previous foucs area
@param {boolean} backwards when `true` it selects the previous focus area
@param {boolean} unRestrainTabIndex when `true`, will not throw an error if tabindex > 0 is encountered
@returns {Promise<void>} resolves when all events are fired
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"prepack": "yarn build",
"postpack": "rimraf addon-test-support/**/*.js public-types",
"clean": "git clean -x -f",
"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",
"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",
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
"lint:js": "eslint --cache .",
"lint:ts": "tsc --noEmit && tsc --noEmit --project type-tests",
Expand Down
10 changes: 10 additions & 0 deletions type-tests/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import {
DebugInfo as InternalDebugInfo,
DeprecationFailure,
Warning,
tab,
} from '@ember/test-helpers';
import { ComponentInstance } from '@glimmer/interfaces';
import { Owner } from '@ember/test-helpers/build-owner';
Expand Down Expand Up @@ -95,6 +96,15 @@ expectTypeOf(select).toEqualTypeOf<
keepPreviouslySelected?: boolean
) => Promise<void>
>();
expectTypeOf(tab).toEqualTypeOf<
({
backwards,
unRestrainTabIndex,
}?: {
backwards?: boolean | undefined;
unRestrainTabIndex?: boolean | undefined;
}) => Promise<void>
>();
expectTypeOf(tap).toEqualTypeOf<
(target: Target, options?: TouchEventInit) => Promise<void>
>();
Expand Down

0 comments on commit 1572779

Please sign in to comment.