Skip to content

Commit

Permalink
fix(modal): support floating menus in modal (carbon-design-system#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
asudoh authored and tw15egan committed Nov 21, 2017
1 parent bbcb5c3 commit e5dca27
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
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

0 comments on commit e5dca27

Please sign in to comment.