Skip to content

Commit

Permalink
[ModalManager] Small refactor for #8741
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 28, 2018
1 parent b74a675 commit a423d45
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
17 changes: 8 additions & 9 deletions packages/material-ui/src/Modal/ModalManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ function findIndexOf(data, callback) {
return idx;
}

function findContainer(data, modal) {
return findIndexOf(data, item => item.modals.indexOf(modal) !== -1);
}

function getPaddingRight(node) {
return parseInt(css(node, 'paddingRight') || 0, 10);
}
Expand Down Expand Up @@ -63,6 +59,7 @@ function removeContainerStyle(data, container) {
fixedNodes[i].style.paddingRight = `${data.prevPaddings[i]}px`;
}
}

/**
* @ignore - do not document.
*
Expand All @@ -71,9 +68,12 @@ function removeContainerStyle(data, container) {
* Used by the Modal to ensure proper styling of containers.
*/
class ModalManager {
constructor({ hideSiblingNodes = true, handleContainerOverflow = true } = {}) {
constructor(options = {}) {
const { hideSiblingNodes = true, handleContainerOverflow = true } = options;

this.hideSiblingNodes = hideSiblingNodes;
this.handleContainerOverflow = handleContainerOverflow;

// this.modals[modalIdx] = modal
this.modals = [];
// this.containers[containerIdx] = container
Expand All @@ -86,8 +86,6 @@ class ModalManager {

add(modal, container) {
let modalIdx = this.modals.indexOf(modal);
const containerIdx = this.containers.indexOf(container);

if (modalIdx !== -1) {
return modalIdx;
}
Expand All @@ -99,6 +97,7 @@ class ModalManager {
hideSiblings(container, modal.mountNode);
}

const containerIdx = this.containers.indexOf(container);
if (containerIdx !== -1) {
this.data[containerIdx].modals.push(modal);
return modalIdx;
Expand Down Expand Up @@ -127,7 +126,7 @@ class ModalManager {
return modalIdx;
}

const containerIdx = findContainer(this.data, modal);
const containerIdx = findIndexOf(this.data, item => item.modals.indexOf(modal) !== -1);
const data = this.data[containerIdx];
const container = this.containers[containerIdx];

Expand All @@ -146,7 +145,7 @@ class ModalManager {
this.containers.splice(containerIdx, 1);
this.data.splice(containerIdx, 1);
} else if (this.hideSiblingNodes) {
// Otherwise make sure the next top modal is visible to a SR.
// Otherwise make sure the next top modal is visible to a screan reader.
ariaHidden(false, data.modals[data.modals.length - 1].mountNode);
}

Expand Down
24 changes: 12 additions & 12 deletions packages/material-ui/test/typescript/styles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ withStyles<'listItem' | 'guttered'>(theme => ({
}));

{
type ListItemContentClassKey = 'root' | 'iiiinset' | 'row'
type ListItemContentClassKey = 'root' | 'iiiinset' | 'row';
const styles = withStyles<ListItemContentClassKey>(
theme => ({
// Styled similar to ListItemText
Expand All @@ -194,7 +194,7 @@ withStyles<'listItem' | 'guttered'>(theme => ({
flex: '1 1 auto',
padding: '0 16px',
},

iiiinset: {
'&:first-child': {
paddingLeft: theme.spacing.unit * 7,
Expand All @@ -207,27 +207,27 @@ withStyles<'listItem' | 'guttered'>(theme => ({
},
}),
{ name: 'ui-ListItemContent' },
)
);

interface ListItemContentProps extends StyledComponentProps<ListItemContentClassKey> {
inset?: boolean
row?: boolean
inset?: boolean;
row?: boolean;
}

const ListItemContent = styles<ListItemContentProps>(props => {
const { children, classes, inset, row } = props
const { children, classes, inset, row } = props;
return (
<div className="foo" color="textSecondary">
{children}
</div>
)
})
);
});
}

{
interface FooProps extends StyledComponentProps<'x' | 'y'> {
a: number
b: boolean
a: number;
b: boolean;
}

const ListItemContent = withStyles({ x: {}, y: {} })<FooProps>(props => <div />);
Expand Down

0 comments on commit a423d45

Please sign in to comment.