-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7922 from stopfstedt/locale-chooser
replace {{did-insert}} modifiers in LocaleChooser component
- Loading branch information
Showing
13 changed files
with
79 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
import { create, collection, triggerable } from 'ember-cli-page-object'; | ||
|
||
import { hasFocus } from 'ilios-common'; | ||
export default create({ | ||
scope: '[data-test-locale-chooser]', | ||
toggle: { | ||
scope: '[data-test-toggle]', | ||
enter: triggerable('keyup', '', { eventProperties: { key: 'Enter' } }), | ||
down: triggerable('keyup', '', { eventProperties: { key: 'ArrowDown' } }), | ||
esc: triggerable('keyup', '', { eventProperties: { key: 'Escape' } }), | ||
hasFocus: hasFocus(), | ||
}, | ||
locales: collection('[data-test-item]', {}), | ||
locales: collection('[data-test-item]', { | ||
hasFocus: hasFocus(), | ||
}), | ||
}); |
2 changes: 1 addition & 1 deletion
2
packages/ilios-common/addon-test-support/ilios-common/helpers/has-focus.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { modifier } from 'ember-modifier'; | ||
|
||
/** | ||
The `{{focus}}` element modifier sets the focus its DOM element. | ||
It can take one optional boolean argument, which can be used to conditionally allow or prevent focusing. | ||
For example - focusing the first item in an ordered list: | ||
```handlebars | ||
<ol> | ||
{{#each @items as |item index|}} | ||
<li {{focus (eq index 0)}}> | ||
{{/each} | ||
</ol> | ||
``` | ||
*/ | ||
export default modifier(function focus(element, positional /*, named*/) { | ||
// If no argument is provided, then the given element is focused on. | ||
// If an argument has been provided, then only set focus if that arg is truthy. | ||
if (!positional.length || !!positional[0]) { | ||
element.focus(); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ilios-common/modifiers/focus'; |
16 changes: 0 additions & 16 deletions
16
packages/test-app/tests/integration/modifiers/autofocus-test.js
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
packages/test-app/tests/integration/modifiers/focus-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'test-app/tests/helpers'; | ||
import { render } from '@ember/test-helpers'; | ||
import { hbs } from 'ember-cli-htmlbars'; | ||
|
||
module('Integration | Modifier | focus', function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test('it focuses by default without condition', async function (assert) { | ||
this.set('label', 'foo bar'); | ||
await render(hbs`<label><input {{focus}} />{{this.label}}</label> | ||
`); | ||
assert.dom('input').isFocused(); | ||
}); | ||
|
||
test('it focuses when condition is met', async function (assert) { | ||
this.set('label', 'foo bar'); | ||
await render(hbs`<label><input {{focus true}} />{{this.label}}</label> | ||
`); | ||
assert.dom('input').isFocused(); | ||
}); | ||
|
||
test('it does not focus when condition is not met', async function (assert) { | ||
this.set('label', 'foo bar'); | ||
await render(hbs`<label><input {{focus false}} />{{this.label}}</label> | ||
`); | ||
assert.dom('input').isNotFocused(); | ||
}); | ||
}); |