Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to configure the initalFocus of the focus-trap in AuModal #326

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addon/components/au-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
isActive=@modalOpen
focusTrapOptions=
(hash
initialFocus=".au-c-modal__title"
initialFocus=this.initialFocus
allowOutsideClick=true
escapeDeactivates=this.handleEscapePress
)
Expand Down Expand Up @@ -65,4 +65,4 @@
{{/if}}
</div>
{{/in-element}}
{{/if}}
{{/if}}
4 changes: 4 additions & 0 deletions addon/components/au-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ export default class AuModal extends Component {
else return '';
}

get initialFocus() {
return this.args.initialFocus ?? '.au-c-modal__title';
}

@action
handleEscapePress() {
this.closeModal();
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,8 @@
"release": true,
"tokenRef": "GITHUB_AUTH"
}
},
"volta": {
"node": "14.20.1"
}
}
7 changes: 7 additions & 0 deletions stories/5-components/Content/AuModal.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default {
description:
'If set to true the modal container and content will be have visible overflow. Useful when using a powerselect component inside a modal.',
},
initialFocus: {
control: 'text',
description: 'Element which should be focused when opening the modal',
},
},
parameters: {
layout: 'fullscreen',
Expand Down Expand Up @@ -75,11 +79,13 @@ const OverflowTemplate = (args) => ({
@size={{this.size}}
@padding={{this.padding}}
@overflow={{this.overflow}}
@initialFocus='.power-select'
>
<:title>{{this.title}}</:title>
<:body>
<AuLabel>Power select (rendered in place)</AuLabel>
<PowerSelect
class='power-select'
@allowClear={{true}}
@searchEnabled={{true}}
@loadingMessage='Aan het laden...'
Expand Down Expand Up @@ -119,4 +125,5 @@ Overflow.args = {
padding: 'default',
overflow: true,
powerselectoptions: singleselects,
initialFocus: '.power-select',
};