Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] UI: Resizing window can lead to modal closing, losing user inputs #5232

Open
2 tasks done
whateverforever opened this issue Apr 15, 2024 · 3 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@whateverforever
Copy link

Describe the bug

If you resize the window with a "Launch Task" modal open, it will close the modal when the layout switches. E.g. making the window snap to the left half of the screen, or a quarter of the screen. This leads to the user inputs disappearing.

Expected behavior

The webpage reflows together with the modal, not deleting my input

Additional context to reproduce

  1. Go to tasks
  2. "Launch Task"
  3. Enter some details in the modal
  4. Resize the window until the layout changes (responsive)
  5. Notice that the user inputs are gone

Screenshots

No response

Are you sure this issue hasn't been raised already?

  • Yes

Have you read the Code of Conduct?

  • Yes
@whateverforever whateverforever added bug Something isn't working untriaged This issues has not yet been looked at by the Maintainers labels Apr 15, 2024
Copy link

welcome bot commented Apr 15, 2024

Thank you for opening your first issue here! 🛠

Copy link

dosubot bot commented Apr 15, 2024

To address the issue where resizing the window causes the "Launch Task" modal to close and lose user inputs, you can implement a solution that preserves the modal state and user inputs across window resizes. This involves storing the modal state and user inputs when the modal is opened and restoring them when the window is resized. Here's how you can do it:

  1. Save Modal State and Inputs: Create functions to save the current state of the modal and the inputs within it. Use localStorage to store this data.

  2. Restore Modal State and Inputs on Resize: Implement a function that restores the modal state and inputs from localStorage when the window is resized.

  3. Hook into Modal Open/Close Events: Ensure that the modal state is saved every time the modal is opened or closed.

Here's a simplified example of how this could be implemented in JavaScript:

// Save modal state and inputs
function saveModalState() {
  const modal = document.getElementById('launchTaskModal');
  const isOpen = !!modal && modal.style.display === 'block';
  const inputs = modal.querySelectorAll('input, textarea');
  const inputValues = Array.from(inputs).map(input => input.value);

  localStorage.setItem('modalState', JSON.stringify({ isOpen, inputValues }));
}

// Restore modal state and inputs
function restoreModalState() {
  const savedState = localStorage.getItem('modalState');
  if (savedState) {
    const { isOpen, inputValues } = JSON.parse(savedState);
    const modal = document.getElementById('launchTaskModal');
    const inputs = modal.querySelectorAll('input, textarea');

    if (isOpen) {
      modal.style.display = 'block';
      inputValues.forEach((value, index) => {
        if (inputs[index]) inputs[index].value = value;
      });
    }
  }
}

// Example event listeners for window resize, modal open, and modal close
window.addEventListener('resize', restoreModalState);
document.getElementById('yourOpenModalButtonId').addEventListener('click', () => {
  document.getElementById('launchTaskModal').style.display = 'block';
  saveModalState();
});
document.getElementById('yourCloseModalButtonId').addEventListener('click', () => {
  document.getElementById('launchTaskModal').style.display = 'none';
  saveModalState();
});

// Restore modal state on page load
document.addEventListener('DOMContentLoaded', restoreModalState);

Adjust the code to match your modal's implementation details, such as the correct IDs and how your modal's visibility is managed. This approach ensures that the user's inputs and the modal's open state are preserved during window resizes, addressing the issue you've encountered.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@jsonporter
Copy link

Ah, I see what you're saying. Unfortunately my team doesn't have the bandwidth to fix this at the moment but we'll keep this as an active issue in our backlog and perhaps someone from the community can pick it up.

@eapolinario eapolinario added help wanted Extra attention is needed and removed untriaged This issues has not yet been looked at by the Maintainers labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants