Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UX: Allow select-kit to have an autofocus option (#12183)
On some modals the main/primary input field is a select-kit component (like `{{email-group-user-chooser}}` on the assign modal), so it makes sense to allow select-kit to steal focus on modals like these. This PR adds an `autofocus` option (default false) that allows select-kit to steal focus when it's rendered.
- Loading branch information
1 parent
7fb4633
commit 0f807ba
Showing
4 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...cripts/discourse/tests/integration/components/select-kit/email-group-user-chooser-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,64 @@ | ||
import componentTest, { | ||
setupRenderingTest, | ||
} from "discourse/tests/helpers/component-test"; | ||
import { discourseModule } from "discourse/tests/helpers/qunit-helpers"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
import selectKit from "discourse/tests/helpers/select-kit-helper"; | ||
|
||
discourseModule( | ||
"Integration | Component | select-kit/email-group-user-chooser", | ||
function (hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
hooks.beforeEach(function () { | ||
this.set("subject", selectKit()); | ||
this.setProperties({ | ||
value: [], | ||
onChange() {}, | ||
}); | ||
}); | ||
|
||
componentTest("autofocus option set to true", { | ||
template: hbs`{{email-group-user-chooser | ||
value=value | ||
onChange=onChange | ||
options=(hash | ||
autofocus=true | ||
) | ||
}}`, | ||
|
||
async test(assert) { | ||
this.subject; | ||
assert.ok( | ||
this.subject.header().el()[0].classList.contains("is-focused"), | ||
"select-kit header has is-focused class" | ||
); | ||
assert.ok( | ||
this.subject.filter().el()[0].querySelector(".filter-input") | ||
.autofocus, | ||
"filter input has autofocus attribute" | ||
); | ||
}, | ||
}); | ||
|
||
componentTest("without autofocus", { | ||
template: hbs`{{email-group-user-chooser | ||
value=value | ||
onChange=onChange | ||
}}`, | ||
|
||
async test(assert) { | ||
this.subject; | ||
assert.ok( | ||
!this.subject.header().el()[0].classList.contains("is-focused"), | ||
"select-kit header doesn't have is-focused class" | ||
); | ||
assert.ok( | ||
!this.subject.filter().el()[0].querySelector(".filter-input") | ||
.autofocus, | ||
"filter input doesn't have autofocus attribute" | ||
); | ||
}, | ||
}); | ||
} | ||
); |
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