When it comes to Material Design Dialog guidelines, there is a gap in addressing dialog width for tablet or desktop sized viewports.
Indeed, the specification does not offer clarity on dialog width for desktops, leading each team to implement its own solution. The Material Design Lite team opts for a fixed width approach as illustrated in the example below,
(function() {
'use strict';
var dialogButton = document.querySelector('.dialog-button');
var dialog = document.querySelector('#dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
dialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])')
.addEventListener('click', function() {
dialog.close();
});
}());
body {
padding-top: 20px;
padding-left: 20px;
box-sizing: border-box;
}
.mdl-dialog {
border: none;
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
width: 280px; }
.mdl-dialog__title {
padding: 24px 24px 0;
margin: 0;
font-size: 2.5rem; }
.mdl-dialog__actions {
padding: 8px 8px 8px 24px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap; }
.mdl-dialog__actions > * {
margin-right: 8px;
height: 36px; }
.mdl-dialog__actions > *:first-child {
margin-right: 0; }
.mdl-dialog__actions--full-width {
padding: 0 0 8px 0; }
.mdl-dialog__actions--full-width > * {
height: 48px;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
padding-right: 16px;
margin-right: 0;
text-align: right; }
.mdl-dialog__content {
padding: 20px 24px 24px 24px;
color: rgba(0,0,0, 0.54); }
<link href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" rel="stylesheet"/>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<button class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button>
<p>
It's worth noting that utilizing full-width inputs requires the <a href="https://github.com/GoogleChrome/dialog-polyfill">Dialog polyfill</a>. This leverages the native dialog element for an optimal user experience.
</p>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">MDL Dialog</h3>
<div class="mdl-dialog__content">
<p>
Showcase of the Material Design Lite dialog component, advocating responsible usage.
</p>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Close</button>
<button type="button" class="mdl-button" disabled>Disabled action</button>
</div>
</dialog>
Conversely, the MDC-Web team embraces using a min-width
constraint of 640px
and a max-width
cap of 865px
. An insightful discussion by the MDL team delves into this unresolved aspect.
The HTML inputs I require on my dialog are simply too small for the default sized dialog. It just looks unrefined and I don't want to stretch my input widths too far either to fill the dialog.
Henceforth, tailored implementation based on your requirements is recommended. You may opt for single full-width inputs or fragmented multiple inputs:
(function() {
'use strict';
var dialogButton = document.querySelector('.dialog-button');
var dialog = document.querySelector('#dialog');
if (! dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
dialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])')
.addEventListener('click', function() {
dialog.close();
});
}());
body {
padding-top: 20px;
padding-left: 20px;
box-sizing: border-box;
}
.mdl-dialog {
border: none;
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14),
0 11px 15px -7px rgba(0, 0, 0, 0.12),
0 24px 38px 3px rgba(0, 0, 0, 0.2);
width: 280px;
}
.mdl-dialog__title {
padding: 24px 24px 0;
margin: 0;
font-size: 2.5rem;
}
.mdl-dialog__actions {
padding: 8px 8px 8px 24px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.mdl-dialog__actions > * {
margin-right: 8px;
height: 36px;
}
.mdl-dialog__actions > *:first-child {
margin-right: 0;
}
.mdl-dialog__actions--full-width {
padding: 0 0 8px 0;
}
.mdl-dialog__actions--full-width > * {
height: 48px;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
padding-right: 16px;
margin-right: 0;
text-align: right;
}
.mdl-dialog__content {
padding: 20px 24px 24px 24px;
color: rgba(0, 0, 0, 0.54);
}
/**/
.mdl-dialog {
width: fit-content;
}
.mdl-dialog__content .mdl-textfield {
width: 100%;
margin-right: 24px;
}
<link href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" rel="stylesheet"/>
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<button class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button>
<p>
Remember that the Dialog component requires the <a href="https://github.com/GoogleChrome/dialog-polyfill">Dialog polyfill</a> in order to function. It takes advantage of the native dialog element to provide the most robust experience possible.
</p>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">MDL Dialog</h3>
<div class="mdl-dialog__content">
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
</form>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Close</button>
<button type="button" class="mdl-button" disabled>Disabled action</button>
</div>
</dialog>
Alternatively, you have the option to incorporate multiple inputs per line within the dialog to utilize available space effectively:
(function() {
'use strict';
var dialogButton = document.querySelector('.dialog-button');
var dialog = document.querySelector('#dialog');
if (!dialog.showModal) {
dialogPolyfill.registerDialog(dialog);
}
dialogButton.addEventListener('click', function() {
dialog.showModal();
});
dialog.querySelector('button:not([disabled])')
.addEventListener('click', function() {
dialog.close();
});
}());
body {
padding-top: 20px;
padding-left: 20px;
box-sizing: border-box;
}
.mdl-dialog {
border: none;
box-shadow: 0 9px 46px 8px rgba(0, 0, 0, 0.14), 0 11px 15px -7px rgba(0, 0, 0, 0.12), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
width: 280px;
}
.mdl-dialog__title {
padding: 24px 24px 0;
margin: 0;
font-size: 2.5rem;
}
.mdl-dialog__actions {
padding: 8px 8px 8px 24px;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
.mdl-dialog__actions>* {
margin-right: 8px;
height: 36px;
}
.mdl-dialog__actions>*:first-child {
margin-right: 0;
}
.mdl-dialog__actions--full-width {
padding: 0 0 8px 0;
}
.mdl-dialog__actions--full-width>* {
height: 48px;
-webkit-flex: 0 0 100%;
-ms-flex: 0 0 100%;
flex: 0 0 100%;
padding-right: 16px;
margin-right: 0;
text-align: right;
}
.mdl-dialog__content {
padding: 20px 24px 24px 24px;
color: rgba(0, 0, 0, 0.54);
}
/**/
.mdl-dialog {
width: fit-content;
min-width: 600px;
}
.mdl-dialog__content .mdl-textfield {
width: 45%;
margin-right: 24px;
}
<link href="https://code.getmdl.io/1.3.0/material.indigo-pink.min.css" rel="stylesheet" />
<script src="https://code.getmdl.io/1.3.0/material.min.js"></script>
<button class="mdl-button mdl-button--raised mdl-js-button dialog-button">Show Dialog</button>
<p>
Remember that the Dialog component requires the <a href="https://github.com/GoogleChrome/dialog-polyfill">Dialog polyfill</a> in order to function. It takes advantage of the native dialog element to provide the most robust experience possible.
</p>
<dialog id="dialog" class="mdl-dialog">
<h3 class="mdl-dialog__title">MDL Dialog</h3>
<div class="mdl-dialog__content">
<form action="#">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="sample3">
<label class="mdl-textfield__label" for="sample3">Text...</label>
</div>
</form>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button">Close</button>
<button type="button" class="mdl-button" disabled>Disabled action</button>
</div>
</dialog>