Skip to content
This repository was archived by the owner on Jun 28, 2021. It is now read-only.

Commit c15e172

Browse files
author
Tommy Leunen
committed
fixes dialog position w/ polyfill
1 parent 628130f commit c15e172

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

docs/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
<link rel="stylesheet" href="prism.css">
1010
<script src="https://npmcdn.com/[email protected]/dist/react.js"></script>
1111
<script src="https://npmcdn.com/[email protected]/dist/react-dom.js"></script>
12+
<script src="https://npmcdn.com/dialog-polyfill/dialog-polyfill.js"></script>
13+
<link rel="stylesheet" type="text/css" href="https://npmcdn.com/dialog-polyfill/dialog-polyfill.css" />
1214
<style>
1315
pre {
1416
position: relative;

docs/pages/dialogs.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Dialogs
22

3-
This component uses [dialog element](https://www.w3.org/TR/2013/CR-html5-20130806/interactive-elements.html#the-dialog-element), which is only supported by Chrome and Opera currently. For other browsers, you need to include a [polyfill](https://github.com/GoogleChrome/dialog-polyfill) in your code.
3+
> This component uses [dialog element](https://www.w3.org/TR/2013/CR-html5-20130806/interactive-elements.html#the-dialog-element), which is only supported by Chrome and Opera currently. For other browsers, you need to include a [polyfill](https://github.com/GoogleChrome/dialog-polyfill) in your code.
4+
5+
> If you're using the `Dialog` component with a full MDL app, you will also need to set a custom `z-index` on the `Layout` to make the `Dialog` be accessible on top of the dark overlay. A value of `100001` is required for this to work.
46
57
## Demo
68

docs/src/DocApp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const templateSections = Object.keys(Templates).map(template => ({
2020
class DocApp extends React.Component {
2121
render() {
2222
return (
23-
<Layout fixedHeader fixedDrawer>
23+
<Layout fixedHeader fixedDrawer style={{ zIndex: 100001 }}>
2424
<Header title="React-MDL">
2525
<Navigation>
2626
<a href="https://github.com/tleunen/react-mdl">

docs/src/PageComponentHelper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default (html) =>
99

1010
const demoJs = document.querySelectorAll('.demo-js');
1111
Array.from(demoJs).forEach(code => eval(code.innerHTML));
12+
13+
const dialogs = document.querySelectorAll('dialog');
14+
[].slice.call(dialogs).forEach(dialog => window.dialogPolyfill.registerDialog(dialog));
1215
}
1316

1417
componentWillUnmount() {

scripts/docs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const DOC_PAGES_DIR = path.join('docs', 'pages');
1515
const DOC_PAGES_DIR_OUTPUT = path.join('docs', 'pages', 'html');
1616

1717
function getCodePenForm(jsx, entireClass) {
18-
const prefix = 'for(const component in ReactMDL) { if(ReactMDL.hasOwnProperty(component)) { window[component] = ReactMDL[component]; } }';
18+
const prefix = 'for(const component in ReactMDL) { if(ReactMDL.hasOwnProperty(component)) { window[component] = ReactMDL[component]; } } dialogPolyfill.registerDialog(document.querySelector("dialog"));';
1919
const suffix = "ReactDOM.render(<Demo />, document.getElementById('demo'))";
2020
const code = (entireClass) ? jsx : `
2121
const Demo = (props) => {
@@ -33,8 +33,8 @@ ${suffix}`;
3333
css: '@import url(https://fonts.googleapis.com/icon?family=Material+Icons);',
3434
js: JS,
3535
js_pre_processor: 'babel',
36-
css_external: 'https://npmcdn.com/react-mdl/extra/material.css',
37-
js_external: 'https://npmcdn.com/[email protected]/dist/react.js;https://npmcdn.com/[email protected]/dist/react-dom.js;https://npmcdn.com/react-mdl/extra/material.js;https://npmcdn.com/react-mdl/out/ReactMDL.js'
36+
css_external: 'https://npmcdn.com/react-mdl/extra/material.css;https://npmcdn.com/dialog-polyfill/dialog-polyfill.css',
37+
js_external: 'https://npmcdn.com/[email protected]/dist/react.js;https://npmcdn.com/[email protected]/dist/react-dom.js;https://npmcdn.com/react-mdl/extra/material.js;https://npmcdn.com/react-mdl/out/ReactMDL.js;https://npmcdn.com/dialog-polyfill/dialog-polyfill.js'
3838
};
3939

4040
const JSONstring = JSON.stringify(data)

src/Dialog/Dialog.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ class Dialog extends React.Component {
1818
if(this.props.open !== prevProps.open) {
1919
if(this.props.open) {
2020
findDOMNode(this).showModal();
21+
22+
// display the dialog at the right location
23+
// needed for the polyfill, otherwise it's not at the right position
24+
const bodyHeight = document.body.clientHeight;
25+
const dialogHeight = this.refs.dialog.clientHeight;
26+
this.refs.dialog.style.position = 'fixed';
27+
this.refs.dialog.style.top = `${(bodyHeight - dialogHeight) / 2}px`;
2128
}
2229
else {
2330
findDOMNode(this).close();
@@ -31,7 +38,7 @@ class Dialog extends React.Component {
3138
const classes = classNames('mdl-dialog', className);
3239

3340
return (
34-
<dialog className={classes} {...otherProps}>
41+
<dialog ref="dialog" className={classes} {...otherProps}>
3542
{children}
3643
</dialog>
3744
);

0 commit comments

Comments
 (0)