Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 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
7 changes: 0 additions & 7 deletions packages/crud/src/vaadin-crud-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,6 @@ class CrudDialog extends DialogBaseMixin(OverlayClassMixin(ThemePropertyMixin(Po
`;
}

/** @protected */
firstUpdated(props) {
super.firstUpdated(props);

this.role = 'dialog';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary anymore, as it's set by DialogBaseMixin

}

/** @private **/
__cancel() {
this.dispatchEvent(new CustomEvent('cancel'));
Expand Down
16 changes: 14 additions & 2 deletions packages/dialog/src/vaadin-dialog-base-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ export const DialogBaseMixin = (superClass) =>
},

/**
* The `role` attribute value to be set on the overlay. Defaults to "dialog".
* The `role` attribute value to be set on the dialog. Defaults to "dialog".
*
* @attr {string} overlay-role
*/
overlayRole: {
type: String,
value: 'dialog',
},
};
}
Expand All @@ -103,6 +102,19 @@ export const DialogBaseMixin = (superClass) =>
overlay.addEventListener('vaadin-overlay-closed', this.__handleOverlayClosed.bind(this));

this._overlayElement = overlay;

if (!this.hasAttribute('role')) {
this.role = 'dialog';
}
}

/** @protected */
updated(props) {
super.updated(props);

if (props.has('overlayRole')) {
this.role = this.overlayRole || 'dialog';
}
}
Comment on lines +106 to 118
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this so you can use role instead of overlayRole.


/** @private */
Expand Down
51 changes: 43 additions & 8 deletions packages/dialog/src/vaadin-dialog-overlay-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
import { setOverlayStateAttribute } from '@vaadin/overlay/src/vaadin-overlay-utils.js';

/**
* @polymerMixin
Expand Down Expand Up @@ -43,6 +44,24 @@ export const DialogOverlayMixin = (superClass) =>
];
}

/**
* Override method from OverlayFocusMixin to use owner as content root
* @protected
* @override
*/
get _contentRoot() {
return this.owner;
}

/**
* Override method from OverlayFocusMixin to use owner as modal root
* @protected
* @override
*/
get _modalRoot() {
return this.owner;
}

/** @protected */
ready() {
super.ready();
Expand All @@ -59,6 +78,22 @@ export const DialogOverlayMixin = (superClass) =>
});
}

/**
* @protected
* @override
*/
_attachOverlay() {
this.showPopover();
}

/**
* @protected
* @override
*/
_detachOverlay() {
this.hidePopover();
}

/** @private */
__createContainer(slot) {
const container = document.createElement('div');
Expand Down Expand Up @@ -99,8 +134,8 @@ export const DialogOverlayMixin = (superClass) =>
this._oldOpenedFooterHeader = opened;

// Set attributes here to update styles before detecting content overflow
this.toggleAttribute('has-header', !!headerRenderer);
this.toggleAttribute('has-footer', !!footerRenderer);
setOverlayStateAttribute(this, 'has-header', !!headerRenderer);
setOverlayStateAttribute(this, 'has-footer', !!footerRenderer);

if (headerRendererChanged) {
if (headerRenderer) {
Expand Down Expand Up @@ -134,7 +169,7 @@ export const DialogOverlayMixin = (superClass) =>

/** @private */
_headerTitleChanged(headerTitle, opened) {
this.toggleAttribute('has-title', !!headerTitle);
setOverlayStateAttribute(this, 'has-title', !!headerTitle);

if (opened && (headerTitle || this._oldHeaderTitle)) {
this.requestContentUpdate();
Expand All @@ -150,7 +185,7 @@ export const DialogOverlayMixin = (superClass) =>
this.headerTitleElement.setAttribute('slot', 'title');
this.headerTitleElement.classList.add('draggable');
}
this.appendChild(this.headerTitleElement);
this.owner.appendChild(this.headerTitleElement);
this.headerTitleElement.textContent = this.headerTitle;
} else if (this.headerTitleElement) {
this.headerTitleElement.remove();
Expand All @@ -167,7 +202,7 @@ export const DialogOverlayMixin = (superClass) =>
if (this.headerContainer) {
// If a new renderer has been set, make sure to reattach the container
if (!this.headerContainer.parentElement) {
this.appendChild(this.headerContainer);
this.owner.appendChild(this.headerContainer);
}

if (this.headerRenderer) {
Expand All @@ -179,7 +214,7 @@ export const DialogOverlayMixin = (superClass) =>
if (this.footerContainer) {
// If a new renderer has been set, make sure to reattach the container
if (!this.footerContainer.parentElement) {
this.appendChild(this.footerContainer);
this.owner.appendChild(this.footerContainer);
}

if (this.footerRenderer) {
Expand Down Expand Up @@ -227,9 +262,9 @@ export const DialogOverlayMixin = (superClass) =>

const value = overflow.trim();
if (value.length > 0 && this.getAttribute('overflow') !== value) {
this.setAttribute('overflow', value);
setOverlayStateAttribute(this, 'overflow', value);
} else if (value.length === 0 && this.hasAttribute('overflow')) {
this.removeAttribute('overflow');
setOverlayStateAttribute(this, 'overflow', null);
}
}
};
11 changes: 4 additions & 7 deletions packages/dialog/src/vaadin-dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,13 @@ export type DialogEventMap = DialogCustomEventMap & HTMLElementEventMap;
*
* ### Styling
*
* `<vaadin-dialog>` uses `<vaadin-dialog-overlay>` internal
* themable component as the actual visible dialog overlay.
*
* See [`<vaadin-overlay>`](#/elements/vaadin-overlay) documentation.
* for `<vaadin-dialog-overlay>` parts.
*
* In addition to `<vaadin-overlay>` parts, the following parts are available for styling:
* The following shadow DOM parts are available for styling:
*
* Part name | Description
* -----------------|-------------------------------------------
* `backdrop` | Backdrop of the overlay
* `overlay` | The overlay container
* `content` | The overlay content
* `header` | Element wrapping title and header content
* `header-content` | Element wrapping the header content slot
* `title` | Element wrapping the title slot
Expand Down
71 changes: 46 additions & 25 deletions packages/dialog/src/vaadin-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,13 @@ export { DialogOverlay } from './vaadin-dialog-overlay.js';
*
* ### Styling
*
* `<vaadin-dialog>` uses `<vaadin-dialog-overlay>` internal
* themable component as the actual visible dialog overlay.
*
* See [`<vaadin-overlay>`](#/elements/vaadin-overlay) documentation.
* for `<vaadin-dialog-overlay>` parts.
*
* In addition to `<vaadin-overlay>` parts, the following parts are available for styling:
* The following shadow DOM parts are available for styling:
*
* Part name | Description
* -----------------|-------------------------------------------
* `backdrop` | Backdrop of the overlay
* `overlay` | The overlay container
* `content` | The overlay content
* `header` | Element wrapping title and header content
* `header-content` | Element wrapping the header content slot
* `title` | Element wrapping the title slot
Expand Down Expand Up @@ -108,32 +105,25 @@ class Dialog extends DialogSizeMixin(

static get styles() {
return css`
:host {
:host,
[hidden] {
display: none !important;
}
`;
}

static get properties() {
return {
/**
* Set the `aria-label` attribute for assistive technologies like
* screen readers. An empty string value for this property (the
* default) means that the `aria-label` attribute is not present.
*/
ariaLabel: {
type: String,
value: '',
},
};
:host([opened]),
:host([opening]),
:host([closing]) {
display: contents !important;
}
`;
}

/** @protected */
render() {
return html`
<vaadin-dialog-overlay
id="overlay"
role="${this.overlayRole}"
popover="manual"
.owner="${this}"
.opened="${this.opened}"
.headerTitle="${this.headerTitle}"
Expand All @@ -144,15 +134,46 @@ class Dialog extends DialogSizeMixin(
@mousedown="${this._bringOverlayToFront}"
@touchstart="${this._bringOverlayToFront}"
theme="${ifDefined(this._theme)}"
aria-label="${ifDefined(this.ariaLabel || this.headerTitle)}"
.modeless="${this.modeless}"
.withBackdrop="${!this.modeless}"
?resizable="${this.resizable}"
restore-focus-on-close
focus-trap
></vaadin-dialog-overlay>
exportparts="backdrop, overlay, header, title, header-content, content, footer"
>
<slot name="title" slot="title"></slot>
<slot name="header-content" slot="header-content"></slot>
<slot name="footer" slot="footer"></slot>
<slot></slot>
</vaadin-dialog-overlay>
`;
}

/** @protected */
updated(props) {
super.updated(props);

if (props.has('headerTitle')) {
this.__applyHeaderTitleAriaLabel();
}
}

/** @private */
__applyHeaderTitleAriaLabel() {
// If there is a header title and no aria-label,
// set the aria-label to the header title.
if (this.headerTitle && !this.ariaLabel) {
this.ariaLabel = this.headerTitle;
this.__useHeaderTitleAriaLabel = true;
}

// If there is no header title and the aria-label was set
// using a header title, remove the aria-label.
if (this.__useHeaderTitleAriaLabel && !this.headerTitle) {
this.ariaLabel = null;
this.__useHeaderTitleAriaLabel = false;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, this is supposed to allow using aria-label instead of headerTitle.

Put this into dialog itself, as DialogBaseMixin is used in CRUD where we need different logic and it doesn't have headerTitle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this can be simplified. If updated doesn't include headerTitle if it's never set, then tracking the state wouldn't be necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If updated doesn't include headerTitle if it's never set

Yes, I think that's the case.

Technically it's possible that ariaLabel is set, then headerTitle is set, and then ariaLabel gets removed - in theory, we probably should then set default ariaLabel based on headerTitle. But it's probably an edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified it for now. A practical case might be to use a different aria-label than the header title, but that seems unlikely.

}

defineCustomElement(Dialog);
Expand Down
Loading