Code Monkey home page Code Monkey logo

ember-promise-modals's People

Contributors

aoumiri avatar dependabot-preview[bot] avatar dependabot[bot] avatar ember-tomster avatar mansona avatar marcoow avatar mikek2252 avatar nickschot avatar pichfl avatar renovate-bot avatar renovate[bot] avatar sebastianhelbig avatar turbo87 avatar zeppelin avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

ember-promise-modals's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency eslint to v8.56.0
  • Update dependency eslint-plugin-ember to v11.12.0
  • Update dependency pnpm to v8.14.0
  • Update dependency ember-source to v5
  • Update dependency ember-try to v3
  • Update dependency eslint-config-prettier to v9
  • Update dependency eslint-plugin-prettier to v5
  • Update dependency eslint-plugin-qunit to v8
  • Update dependency postcss-preset-env to v9
  • Update dependency prettier to v3
  • Update dependency qunit-dom to v3
  • Update dependency release-it to v17
  • Update dependency sinon to v17
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • pnpm/action-setup v2.4.0
  • actions/setup-node v3
  • actions/checkout v3
  • pnpm/action-setup v2.4.0
  • actions/setup-node v3
  • actions/checkout v3
  • pnpm/action-setup v2.4.0
  • actions/setup-node v3
.github/workflows/deploy.yml
  • actions/checkout v3.6.0
  • JamesIves/github-pages-deploy-action v4.5.0
.github/workflows/release.yml
  • actions/checkout v3
  • actions/setup-node v3
npm
package.json
  • @ember/test-waiters ^3.0.1
  • @embroider/util ^1.7.1
  • broccoli-funnel ^3.0.8
  • broccoli-merge-trees ^4.2.0
  • broccoli-postcss ^6.0.1
  • ember-auto-import ^2.4.2
  • ember-cli-babel ^7.26.11
  • ember-cli-htmlbars ^6.0.1
  • focus-trap ^6.9.3
  • postcss-preset-env ^7.6.0
  • @babel/eslint-parser 7.23.3
  • @ember/optional-features 2.0.0
  • @ember/string 3.1.1
  • @ember/test-helpers 2.9.4
  • @embroider/test-setup 3.0.3
  • @release-it-plugins/lerna-changelog 5.0.0
  • broccoli-asset-rev 3.0.0
  • ember-cli 4.12.2
  • ember-cli-dependency-checker 3.3.2
  • ember-cli-inject-live-reload 2.1.0
  • ember-cli-sri 2.1.1
  • ember-cli-terser 4.0.2
  • ember-disable-prototype-extensions 1.1.3
  • ember-load-initializers 2.1.2
  • ember-maybe-import-regenerator 1.0.0
  • ember-qunit 8.0.2
  • ember-resolver 8.1.0
  • ember-source 4.12.3
  • ember-source-channel-url 3.0.0
  • ember-template-lint 5.3.3
  • ember-try 2.0.0
  • eslint 8.55.0
  • eslint-config-prettier 8.10.0
  • eslint-plugin-ember 11.11.1
  • eslint-plugin-import-helpers 1.3.1
  • eslint-plugin-node 11.1.0
  • eslint-plugin-prettier 4.2.1
  • eslint-plugin-promise 6.1.1
  • eslint-plugin-qunit 7.3.4
  • loader.js 4.7.0
  • npm-run-all 4.1.5
  • prettier 2.8.8
  • qunit 2.20.0
  • qunit-console-grouper 0.3.0
  • qunit-dom 2.0.0
  • release-it 15.11.0
  • sinon 15.2.0
  • webpack 5.89.0
  • node 12.* || >= 16.*
regex
.github/workflows/ci.yml
  • pnpm 8.11.0

  • Check this box to trigger a request for Renovate to run again on this repository

Latest focus trap changes causes the modal response to be lost

The recent change to how the focus trap is set up (PR #549) is causing issues when you expect the close action to return a value.

Specifically this change in the modal component on lines 103-105:
https://github.com/simplabs/ember-promise-modals/pull/549/files#diff-f1bdcfc6adc126290ecb2862332b13bf329fcd5a397b3ab6210de2911dc65d54L93-R105

Not passing in null here as it did before changes the behaviour in such a way that the focus trap's onDeactivate function calls closeModal again (without return value this time) and resolves the modal before the original @close action call has a chance to resolve with the return value that was passed in.

So currently, this happens:

  1. A link in your modal calls @close
  2. Internally the modal then calls closeModal(result) with the result passed to @close
  3. This then runs focusTrap.deactivate() which immediately runs the onDeactivate function
  4. closeModal() is called again, but without the passed in result this time.
  5. The modal resolves with the undefined result before closeModal(result) from step 2 has a chance to resolve with its data.

Reverting lines 103-105 linked above makes it work properly again, though that probably breaks something else that the PR fixed?

Another workaround might be to set onDeactivate to null through the open() call or globally on the modals service, but that feels like it shouldn't be necessary.

Should we allow calling the close callback more than once?

Hi!

@herzzanu and me have investigated a flaky test in a huge app.

After some frustrating investigation we have discovered, that the cause of test failures was that a modal's @close callback was called twice.

The frustration was caused by trhee parts:

  • everything is async, so the stack trace points at a promise that had been caught by Ember Backburner or something, and the stack trace does not point at the code of the promise callback;
  • we have a chain of ember-concurrency tasks threading through multiple components; a modal is opening a modal, etc;
  • tests never failed locally when the browser tab was focused; tests would sometimes fail when the tab was not focused. ๐Ÿคฏ

The specific error turned out to be "calling set on destroyed object", with stack trace pointing at this line:
https://github.com/mainmatter/ember-promise-modals/blob/v4.0.0/addon/components/modal.js#L148

The solution on our side was to make sure the modal was not being closed twice.

But I wonder, if this should even be a developer's concern? Why not let developers close the modal more than once?

At the very least, we could wrap the set into if (!this.isDestroying && !this.isDestroyed). Or we could make the close callback return early if it is called more than once.

Modal stays in DOM after closing

When closing via click on the container, the modal gets "hidden" but stays in the DOM. This essentially disables all interaction with the application which then has to be reloaded to work again.

It does not always happen, but most of the time.

Screencast Chrome 102 Mac with the demo app:
https://user-images.githubusercontent.com/5049311/170370725-1b7b6ef4-29d7-467d-8e99-132d645e7fcb.mp4

I also did some debugging as in one project I often see timeouts in qunit tests with modals. It turned out that when a timeout happens, the event animationend is not being triggered which leads to not calling modal._remove() which leads to not resolving the promise. I am unsure if this is related or another problem.

Move to v2 addon format

  • Update ember-auto-import to v2 (breaking change)
  • Update to v2 format (requires ember-auto-import v2)

Focus is immediately applied on open, may cause trouble!

Currently we immediately apply the focus-trap even if an animation is still about to happen. This may cause problems if something like an ember-tether is rendered inside the modal as the modal might still be moving.

This could be solved by utilizing the checkCanFocusTrap hook: https://github.com/focus-trap/focus-trap#createoptions . We can pass it a promise that resolves once the animation is complete.

We might want similar behaviour when closing the modal

testWaiter.endAsync fails (needs reproduction)

Error: testWaiter.endAsync called with no preceding testWaiter.beginAsync call.
Test waiter calls should always be paired. This can occur when a test waiter's paired calls are invoked in a non-deterministic order.

Hapens in a larger codebase with setupPromiseModals(hooks); enabled. Needs further investigation.

Add ability to abort modal close

We're currently running a fork of ember-promise-modals but it looks like most of our changes are now possible using the official addon. Our one remaining custom change is the addition of a beforeClose modal option.

Our typical use-case for beforeClose is when we have modal UI that allows user input, when that modal is closed if there are unsaved changes we want to abort the close and open another modal to get confirmation.

Simplified example:

setupController(controller, model) {
    this.newsletterModal = this.modals.open(
        EditNewsletterModal,
        {newsletter: model},
        {beforeClose: this.confirmUnsavedChanges}
    );
}

async confirmUnsavedChanges() {
    if (!this.model.hasDirtyAttributes) { return true; }

    // result: true = close and discard, false = abort close, allow further edits and save
    this.confirmModal = this.modals.open(ConfirmUnsavedChangesModal);

    return this.confirmModal;
}

Does something like this sound like an appropriate addition? Is there something like this already available that I've missed?

Our implementation in the fork was very basic and can be seen in this commit.

Option to opt-out from Focus Trap

Some addons like Ember Power Select render outside the component they're invoked in, making it impossible to use with EPM. (Although EPS can be forced to render in place, but could be difficult to deal with for various reasons). I saw no option in Focus Trap to exclude certain selectors.

I know it would reduce accesibility, but spending time with code that handle modals if we don't have EPM also takes away precious time we could otherwise spend with making our app more accessible.

It doesn't even have to be public API, just an option that's one would only use if really needed it.

Should I open a PR?

`prefer-reduced-motion` stops modals from closing on `main`

Calling close() on the modal from the outside doesn't seem to close the modal if prefer-reduced-motion is enabled on the system and if that applies a 0s duration through CSS media queries. The modal elements are left in the DOM. If I set a non-0s duration, for example 0.01s, then it works.

If however close() is called from inside the modal, then it works fine and the modal elements are removed from the DOM no matter what duration is used. With the 3.0.1 release it broke if you clicked the backdrop to close, but this seems to be fixed in the main branch.

So TLDR: A workaround seems to be to not set a 0s duration, such as 0.01s. Then everything works fine even with 3.0.1.

Originally posted by @bitwolfe in #665 (comment)

Update CI config to include ember 4

We're already ember 4 compatible and implicitly testing against it through ember-release, ember-beta etc. but would be good to add 4.0.0 to the CI config explicitly.

Decorator being a barrier to be able to use it with previous Ember versions

Converting ember-promise-modals/modal to a classic Ember Object would expand support to even earlier Ember versions. Huge codebases that struggle with updating could benefit greatly from EPM, and from what I observed, that part of the addon is not performance-critical.

We're patching EPM in our project at the moment. Do you accept PRs? :)

focus should return to origin element when modal is closed

Environment

This happens on a PC in both Firefox and Chrome.

What I expect to happen

ESC and the close button should both close the modal and return focus to the element that opened the modal.

What happens

  • When I press ESC and close the modal, the focus (correctly) returns to the button that opened the modal.
  • When I interact with the "close" button to close the modal, focus is not returned to the button that opened the modal.

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.