DEV: Add autofocus option to d-menu (#26829)

(to be used by the glimmer replacement of topic-entrance component)
This commit is contained in:
Jarek Radosz 2024-05-01 12:11:11 +02:00 committed by GitHub
parent 3a69824ffb
commit b39736a167
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 15 additions and 1 deletions

View File

@ -242,4 +242,17 @@ module("Integration | Component | FloatKit | d-menu", function (hooks) {
assert.dom(".fk-d-menu").doesNotExist();
});
test("@autofocus", async function (assert) {
await render(hbs`
<DMenu @inline={{true}} @autofocus={{true}}>
<:content>
<DButton class="my-button" />
</:content>
</DMenu>
`);
await open();
assert.dom(document.activeElement).hasClass("my-button");
});
});

View File

@ -63,7 +63,7 @@ export default class DFloatBody extends Component {
aria-expanded={{if @instance.expanded "true" "false"}}
role={{@role}}
{{FloatKitApplyFloatingUi this.trigger this.options @instance}}
{{(if @trapTab (modifier TrapTab autofocus=false))}}
{{(if @trapTab (modifier TrapTab autofocus=this.options.autofocus))}}
{{(if
this.supportsCloseOnClickOutside
(modifier FloatKitCloseOnClickOutside this.trigger @instance.close)

View File

@ -46,6 +46,7 @@ export const MENU = {
options: {
animated: true,
arrow: false,
autofocus: false,
beforeTrigger: null,
closeOnEscape: true,
closeOnClickOutside: true,