Skip to content

Commit

Permalink
add the option to configure the initalFocus of the focus-trap in aumodal
Browse files Browse the repository at this point in the history
  • Loading branch information
elpoelma committed Sep 29, 2022
1 parent 8cfd6b5 commit 423cd97
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
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',
};

0 comments on commit 423cd97

Please sign in to comment.