Giter Site home page Giter Site logo

vaadin / vaadin-dialog Goto Github PK

View Code? Open in Web Editor NEW
15.0 19.0 8.0 5.14 MB

High quality web component for modal dialogs. Part of the Vaadin platform.

Home Page: https://vaadin.com/components

License: Apache License 2.0

JavaScript 3.64% HTML 96.36%
dialog webcomponents web-component polymer polymer-element polymer2 vaadin

vaadin-dialog's Introduction

<vaadin-dialog>

⚠️ Starting from Vaadin 20, the source code and issues for this component are migrated to the vaadin/web-components monorepository. This repository contains the source code and releases of <vaadin-dialog> for the Vaadin versions 10 to 19.

<vaadin-dialog> is a Web Component for customized modal dialogs, part of the Vaadin components.

Live Demo ↗ | API documentation ↗

npm version Bower version Published on webcomponents.org Build Status Coverage Status Published on Vaadin  Directory Stars on vaadin.com/directory

<vaadin-dialog opened>
</vaadin-dialog>

<script>
  const dialog = document.querySelector('vaadin-dialog');
  dialog.renderer = function(root, dialog) {
    root.textContent = 'Sample dialog';
  };
</script>

Screenshot of vaadin-dialog

Installation

The Vaadin components are distributed as Bower and npm packages. Please note that the version range is the same, as the API has not changed. You should not mix Bower and npm versions in the same application, though.

Unlike the official Polymer Elements, the converted Polymer 3 compatible Vaadin components are only published on npm, not pushed to GitHub repositories.

Polymer 2 and HTML Imports Compatible Version

Install vaadin-dialog:

bower i vaadin/vaadin-dialog --save

Once installed, import it in your application:

<link rel="import" href="bower_components/vaadin-dialog/vaadin-dialog.html">

Polymer 3 and ES Modules Compatible Version

Install vaadin-dialog:

npm i @vaadin/vaadin-dialog --save

Once installed, import it in your application:

import '@vaadin/vaadin-dialog/vaadin-dialog.js';

Getting started

Vaadin components use the Lumo theme by default.

To use the Material theme, import the correspondent file from the theme/material folder.

Entry points

  • The component with the Lumo theme:

    theme/lumo/vaadin-dialog.html

  • The component with the Material theme:

    theme/material/vaadin-dialog.html

  • Alias for theme/lumo/vaadin-dialog.html:

    vaadin-dialog.html

Running demos and tests in a browser

  1. Fork the vaadin-dialog repository and clone it locally.

  2. Make sure you have npm and Bower installed.

  3. When in the vaadin-dialog directory, run npm install and then bower install to install dependencies.

  4. Run npm start, browser will automatically open the component API documentation.

  5. You can also open demo or in-browser tests by adding demo or test to the URL, for example:

Running tests from the command line

  1. When in the vaadin-dialog directory, run polymer test

Following the coding style

We are using ESLint for linting JavaScript code. You can check if your code is following our standards by running npm run lint, which will automatically lint all .js files as well as JavaScript snippets inside .html files.

Big Thanks

Cross-browser Testing Platform and Open Source <3 Provided by Sauce Labs.

Contributing

To contribute to the component, please read the guideline first.

License

Apache License 2.0

Vaadin collects development time usage statistics to improve this product. For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.

vaadin-dialog's People

Contributors

abhishekmattoria avatar artur- avatar dependabot[bot] avatar diegocardoso avatar haprog avatar jouni avatar limonte avatar manolo avatar marcushellberg avatar paivisoinio avatar platosha avatar samiheikki avatar sohrabtaee avatar someonetoignore avatar sosa-vaadin avatar tomivirkki avatar vicsstar avatar web-padawan avatar yuriy-fix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vaadin-dialog's Issues

Child elements should not be inside shadow-root

Child elements should not be inside shadow root. This makes e.g. browser's password saving feature not work if login details are entered into fields that are shown inside vaadin-dialog.

Either always have the child elements outside the shadow-root or have a mode where the child elements are outside shadow-root.

screenshot from 2018-02-12 12-12-46

Hard-coded overlay style with content padding

Currently, vaadin-dialog.html contains hard-coded style with padding for the overlay content:

<dom-module id="vaadin-dialog-styles" theme-for="vaadin-dialog-overlay">
  <template>
    <style>
      [part="content"] {
        padding: 5px;
      }
    </style>
  </template>
</dom-module>

This gets combined with theme styles, making the padding hard to customize in the theme.

Sugested fix: rename the style module to vaadin-dialog-overlay-default-theme.

Styles inside the dialog template should be scoped

At the moment, if you place a <style> element in the dialog template, those styles will end up in the global scope in browsers without native shadow dom.

In Firefox, the following will make the body background red when the dialog is opened:

<vaadin-dialog>
  <template>
    <style>
      body {
        background: red !important;
      }
    </style>
  </template>
</vaadin-dialog>

renderer is called twice

Given a component with

      <vaadin-dialog id="editorDialog" no-close-on-outside-click no-close-on-esc></vaadin-dialog>

and

    this.editView = document.createElement("users-edit-view");
    this.editorDialog.renderer = (container) => {
      console.log("Rendering contents of dialog");
      container.appendChild(this.editView);
    };

and some logging statements will produce the following output

15:49:19.311 users-view.js:67 Setting dialog renderer
15:49:20.767 users-view.js:70 Rendering contents of dialog
15:49:20.838 users-edit-view.js:47 users-edit-view ready
15:49:20.838 users-edit-view.js:57 users-edit-view connected
15:49:20.839 users-view.js:70 Rendering contents of dialog
15:49:20.841 users-edit-view.js:52 users-edit-view disconnected
15:49:20.842 users-edit-view.js:57 users-edit-view connected
15:49:20.852 users-view.js:74 Renderer was set

Update styling documentation

The Styling API documentation seems to be outdated (parts for “backdrop” and “content”, but not for “overlay”)

not working with vaadin-grid and context menu.

This following code does not work.


<dom-module id="my-dom">
    <template>
        <style is="custom-style">
            vaadin-grid {
                --vaadin-grid-body-cell: {
                    padding: 0;
                };
            }
            .body-content {
                padding: 8px;
            }
        </style>
            <vaadin-context-menu>
              <template>
                <paper-listbox>
                  <paper-item on-tap="_add">Add</paper-item>
                  <template is="dom-if" if="[[_isGridBody(target)]]">
                    <paper-item content="[[target]]" on-tap="_remove">Remove</paper-item>
                  </template>
                </paper-listbox>
              </template>

              <vaadin-grid id="grid" items="[[items]]">

                <vaadin-grid-column>
                  <template class="header">Name</template>
                  <template>
                    <div class="body-content" data-index$="[[index]]">[[item.name]]</div>
                  </template>
                </vaadin-grid-column>

                <vaadin-grid-column>
                  <template class="header">Surname</template>
                  <template>
                    <div class="body-content" data-index$="[[index]]">[[item.surname]]</div>
                  </template>
                </vaadin-grid-column>

                <vaadin-grid-column>
                  <template class="header">Effort</template>
                  <template>
                    <div class="body-content" data-index$="[[index]]">[[item.effort]]</div>
                  </template>
                </vaadin-grid-column>

              </vaadin-grid>

            </vaadin-context-menu>
                    <vaadin-dialog id="dialog" no-close-on-esc no-close-on-outside-click>
                        <template>
                            <div>Press any button to close</div>
                            <br>
                            <isp-content></isp-content>
                            <vaadin-button on-click="closeDialog">Ok</vaadin-button>
                            <vaadin-button on-click="closeDialog">Cancel</vaadin-button>
                        </template>
                    </vaadin-dialog>
                    <!--paper-dialog id="dialog" modal>
                        <h2>Dialog Title</h2>
                        <p> Hello World</p>
                        <div class="buttons">
                            <paper-button dialog-confirm autofocus>Tap me to close</paper-button>
                        </div>
                    </paper-dialog-->
    </template>
    <script>
        Polymer({
            is: "my-dom",
            properties: {
                items: {
                    type: Array,
                    value: function() {
                        return getItems();
                    }
                }
            },
            ready: function() {
                console.log("my-dom ready");
            },
            _isGridBody: function(target) {
                return target.classList.contains("body-content");
            },
            _add: function() {
                this.unshift('items', getNewItem());
                this.$.dialog.open();
            },
            _remove: function(e) {
                var index = parseInt(e.target.content.getAttribute('data-index'));
                this.splice('items', index, 1);
            },
            closeDialog: function() {
                this.$.dialog.opened = false;
            }
        });
        function getNewItem() {
            function random(arr) {
                return arr[Math.floor(Math.random() * arr.length)];
            }
            var names = ['Artur', 'Patrik', 'Henrik', 'Teemu'];
            var surnames = ['Signell', 'Lehtinen', 'Ahlroos', 'Paul'];
            return {
                name: random(names),
                surname: random(surnames),
                effort: Math.floor(Math.random() * 6)
            };
        }
        function getItems() {
            var items = [];
            for (var i = 0; i < 100; i++) {
                items.push(getNewItem());
            }
            return items;
        }
    </script>
   </dom-module>

I am trying to display a vaadin-dialog on context-menu click(Add option). The dialog appears for the first time. But after that the context menu does not show at all. Same is the case with paper-dialog.

Code examples look convoluted

The examples look bloated/convoluted with long variable names and dom-binds. The benefit of using a dom-bind is really trivial when we are just setting a few event listeners. The examples would IMO look a lot simpler if we just used standard JavaScript.

Use overlay 3.0

  • Start from proto/style-gather
  • Add a demo on how to style the dialog content

Npm version of vaadin dialog installs dependencies as "children" instead of as siblings

When installing vaadin dialog with npm, it's creating a child node-modules folder with its dependencies, instead of installing its dependencies as siblings inside node modules like other vaadin elements.

This is a big problem while using it in the same project with vaadin-date-picker because both depend on vaadin-overlay and while testing locally or deploying you end up with this error: Uncaught (in promise) DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry

Here are some images to show what I mean:

This is how other elements install dependencies (in this case vaadin-date-picker)
vaadin normal

And this is how vaadin dialog does it
vaadin dialog

Dialog has native outline on the overlay part

The overlay focus behavior has been changed in vaadin/vaadin-overlay#69
This affected the dialog as the only component using focus-trap, as of now:

screen shot 2018-03-23 at 19 24 21

I'd suggest fixing this here because of the fact that the overlay is the generic element, and as such it probably shouldn't decide anything about the native outline.

Shared styles with vaadin-dialog

Hello,
I tried to use shared style module with vaadin-dialog, but is this supported by vaadin/polymer?

    <vaadin-dialog id="actions-upload" opened="{{uploadDialogOpened}}">
        <template>
            <style include="shared-styles">
             .foo-elem{}
             ...

I tried styling my dialog contents as in example above, and while styles were applied to my element, only things that were inside style tag were present so .foo-elem worked, the styles from shared-styles module were not being applied at all to the contents.

Support style modules inside the dialog template

In order to have a sensible way to style the dialog contents, we need to support style modules. Without that support, the only way to provide styles for the dialog contents is to make the contents into a Polymer element itself and include style modules there.

The following should be possible:

<link rel="import" href="bower_components/vaadin-lumo-styles/typography.html">
<link rel="import" href="bower_components/vaadin-lumo-styles/color.html">

<vaadin-dialog>
  <template>
    <style include="lumo-typography lumo-color"></style>
    <h2>Dialog title</h2>
    <p>The title and this paragraph should have the correct styles defined by Lumo</p>
  </template>
</vaadin-dialog>

Added wrapper elements should have a way to configure CSS properties

<flow-component-renderer> and its child <div> prevents flex configured in it's container vaadin-dialog-overlay to apply to the dialog content.

We need this workaround, which is an anti-pattern in the theme customisation because the user needs to know implementation details.

https://github.com/vaadin/bakery-app-starter-flow-spring/blob/fix/570-remove-form-dialog/src/main/webapp/frontend/src/styles/shared-styles.html#L60

I don't know what is the best option but some ideas

  • Use some javascript to figure-out its parent computed flex styles and apply to flow-component-renderer and div
  • Set a default CSS display: flex; flex: auto; that might be valid for most cases
  • flow-component-renderer might be themable with a part=content targeting the div wrapper.

[FR]: Provide a way for adding arbitrary content programatically

When using dialogs from server side, it might be useful to have an imperative way for adding content.

In JS could be something like:

const e = document.createElement('div')
e.innerText = 'Click me'
e.addEventListener('click', () => console.log('click'))
dialog.appendChild(e);

In java side it should be quite easy to set content that already is bound to events

MyCElement e = new MyCElement();
e.addEventListener('click', ...);
dialog.getElement().appendChild(e);

Allow adding elements to the dialog by using <slot> instead of <template>

Currently there's no way of adding arbitrary elements inside the dialog - you must instead create a template on how the inner elements should be generated, and then Polymer creates the elements for you.

That's bad for integrations with frameworks that need to manage internal components to provide their features. Also, it makes the usage pretty different from what we have with paper-dialog currently (it uses slots).

Consider a way to theme the internal overlay

It would be nice to have different themes for different dialog instances e.g left, right, center.
The problem is that setting theme to the dialog component, there is no way to target the internal overlay.

Having an attribute in the element that is reflected to the overlay like orientation or even theme would be a solution

Fix demos to be touch device friendly

Dialog demos are not touch device friendly, they should be so that tapping outside the dialog would dismiss the dialog unless that has been explicitly disabled (true modal dialog, but then there need to be a way to dismiss the dialog inside the dialog itself)

allow setting aria-label / aria-labelledby attributes for screen readers

As a screen reader user I want to hear a short descriptive title of the dialog instead of its entire contents when a dialog opens. As a developer I want to support such users by setting an aria-label or aria-labelledby attribute on the dialog element (the element that has role="dialog"). As of now <vaadin-dialog> does not support setting it.

The 'simple dialog' demo at https://vaadin.com/components/vaadin-dialog/html-examples/dialog-basic-demos shows that:

I would expect that setting an aria-label attribute would affect how screen readers read the dialog. It does not:

<vaadin-dialog aria-label="simple">
  <template>
    <div>This simple dialog will close by pressing the Esc key,</div>
    <div> or by a mouse click anywhere outside the dialog area</div>
  </template>
</vaadin-dialog>

That causes screen readers to read the contents of the dialog twice: once as a title and the second time as the contents:

NVDA:

Dialog: This simple dialog will close by pressing the Esc key, or by a mouse click anywhere outside the dialog area.
This simple dialog will close by pressing the Esc key, or by a mouse click anywhere outside the dialog area.

JAWS:

"This simple dialog will close by pressing the Esc key, or by a mouse click anywhere outside the dialog area" dialog.
This simple dialog will close by pressing the Esc key, or by a mouse click anywhere outside the dialog area.

VoiceOver:

This simple dialog will close by pressing the Esc key, or by a mouse click anywhere outside the dialog area. Dialog.
This simple dialog will close by pressing the Esc key, or by a mouse click anywhere outside the dialog area. Group.

Re-enable IE11 tests

Currently just white screen appears in SauceLabs' IE11 browser, no errors in console.

Focus trap does not work inside shadow-root

When you put an element in the dialog, with focusable elements in its shadow-root those elements are not focusable with keyboard.

You can test it by adding a vaadin-date-picker to a dialog.

A better implementation for focus trap might be not listening to keyboard events, but prevent moving the focus when the dialog is about to blur

Tabbing between fields does not work in certain cases

When creating a dialog as

<vaadin-dialog id="editorDialog" no-close-on-outside-click no-close-on-esc></vaadin-dialog>

and

this.editView = document.createElement("my-edit-view");
this.editorDialog.renderer = (container) => {
    container.appendChild(this.editView);
};

Where my-edit-view contains

<h3>Edit user</h3>
<vaadin-form-layout>
    <vaadin-text-field id="firstName" label="First Name"></vaadin-text-field>
    <vaadin-text-field id="lastName" label="Last Name"></vaadin-text-field>
    <vaadin-text-field colspan=2 id="email" label="Email"></vaadin-text-field>
    <vaadin-password-field colspan=2 id="newPassword" label="Password"></vaadin-password-field>
    <vaadin-combo-box colspan=2 id="role" label="Role"></vaadin-combo-box>
</vaadin-form-layout>

I end up with a dialog where tab does not work at all. Whenever you press tab, the focus goes to the overlay element itself.

X to close Dialog

Hi guys,

Is there any built in mark up to lose a dialogs by an x in the top corner?

Fix UX result report

UX test for dialog does not say if/what feedback has been taken into account if any

Flow API related todo list

Polymer.Element APIs leaking to analysis and API docs

  • Workaround: class VaadinDialog extends (class extends Polymer.Element {})
  • Update analysis.json

Mark with @private for the element classes

  • vaadin-dialog.html:
    • class VaadinDialogOverlay

A way to get the element from js

Hello Vaadin team, thx for your component.

In some case we have to access to the element after that it was embedded in the dialog.

I have wrote this method : RoXuS@89093f1

Is there another way ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.