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

fix(modal): support floating menus in modal #430

Merged
merged 1 commit into from
Nov 21, 2017
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
2 changes: 1 addition & 1 deletion src/components/card/_card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
position: absolute;
top: 1rem;
right: 1rem;
z-index: z('overflowOptions');
z-index: z('floating');
margin: 0;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/components/modal/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ class Modal extends mixin(createComponent, initComponentByLauncher, eventedShowH
* @private
*/
_handleFocusin = evt => {
if (this.element.classList.contains(this.options.classVisible) && !this.element.contains(evt.target)) {
if (
this.element.classList.contains(this.options.classVisible) &&
!this.element.contains(evt.target) &&
this.options.selectorsFloatingMenus.every(selector => !eventMatches(evt, selector))
) {
this.element.focus();
}
};
Expand Down Expand Up @@ -148,6 +152,9 @@ class Modal extends mixin(createComponent, initComponentByLauncher, eventedShowH
* @type {Object}
* @property {string} selectorInit The CSS class to find modal dialogs.
* @property {string} attribInitTarget The attribute name in the launcher buttons to find target modal dialogs.
* @property {string[]} [selectorsFloatingMenu]
* The CSS selectors of floating menus.
* Used for detecting if focus-wrap behavior should be disabled temporarily.
* @property {string} [classVisible] The CSS class for the visible state.
* @property {string} [classNoScroll] The CSS class for hiding scroll bar in body element while modal is shown.
* @property {string} [eventBeforeShown]
Expand All @@ -167,6 +174,7 @@ class Modal extends mixin(createComponent, initComponentByLauncher, eventedShowH
selectorInit: '[data-modal]',
selectorModalClose: '[data-modal-close]',
selectorPrimaryFocus: '[data-modal-primary-focus]',
selectorsFloatingMenus: ['.bx--overflow-menu-options', '.bx-tooltip'],
classVisible: 'is-visible',
attribInitTarget: 'data-modal-target',
initEventNames: ['click'],
Expand Down
2 changes: 1 addition & 1 deletion src/components/overflow-menu/_overflow-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
flex-direction: column;
align-items: flex-start;
position: absolute;
z-index: 1;
z-index: z('floating');
background-color: $inverse-01;
border: 1px solid $ui-04;
width: 11.25rem;
Expand Down
1 change: 1 addition & 0 deletions src/components/tooltip/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
background: $ui-01;
padding: 1.5rem;
border: 1px solid $ui-04;
z-index: z('floating');

p {
@include font-family;
Expand Down
2 changes: 1 addition & 1 deletion src/globals/scss/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $z-indexes: (
footer : 5000,
hidden : - 1,
overflowHidden: - 1,
overflowOptions: 1
floating: 10000
);

//-------------------------------------
Expand Down
1 change: 1 addition & 0 deletions tests/spec/modal_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('Test modal', function() {
selectorInit: '[data-modal]',
selectorModalClose: '[data-modal-close]',
selectorPrimaryFocus: '[data-modal-primary-focus]',
selectorsFloatingMenus: ['.bx--overflow-menu-options', '.bx-tooltip'],
classVisible: 'is-visible',
attribInitTarget: 'data-modal-target',
initEventNames: ['click'],
Expand Down