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: the modal is not work. #29

Open
ichenhua opened this issue Dec 14, 2024 · 8 comments
Open

bug: the modal is not work. #29

ichenhua opened this issue Dec 14, 2024 · 8 comments

Comments

@ichenhua
Copy link

What version of FlyonUI are you using?

v1.2.0

Which browsers are you seeing the problem on?

No response

Reproduction URL

https://flyonui.com/docs/overlays/modal/#basic-examples

Describe your issue

I tried to launch model-target with openbtn, but it didn't work.

<div id="modal-target" class="overlay modal overlay-open:opacity-100 modal-middle hidden">
    <div class="modal-dialog overlay-open:opacity-100">
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title">Dialog Title</h3>
                <button type="button" class="btn btn-text btn-circle btn-sm absolute end-3 top-3" aria-label="Close" data-overlay="#middle-center-modal">
                    <span class="icon-[tabler--x] size-4"></span>
                </button>
            </div>
            <div class="modal-body">
                This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text in the
                modal, we use an inline style to set a minimum height, thereby extending the length of the overall modal and
                demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling
                will move the modal as needed.
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-soft btn-secondary" data-overlay="#middle-center-modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

<button id="open-btn" type="button" data-overlay="#modal-target" class="btn btn-primary --prevent-on-load-init">Open modal using methods</button>
<script src="path/to/overlay.js"></script>
<script>
    window.addEventListener('load', function () {
        const openBtn = document.querySelector('#open-btn');
        openBtn.addEventListener('click', () => {
            alert(111111)
            HSOverlay.open('#modal-target');
        });
    })
</script>
Copy link

Hi @ichenhua

Thank you for your support in helping us improve FlyonUI!

We’ve received your submission and will respond within few business days. Our team handles issues one at a time, and we’ll be reviewing yours as soon as possible.

In the meantime, any additional details or a reproducible example would be greatly appreciated and will help us resolve the issue more efficiently.

Thank you for your patience and understanding!

@ichenhua
Copy link
Author

ichenhua commented Dec 14, 2024

<script>
    document.addEventListener('DOMContentLoaded', function () {
        HSOverlay.open('#modal-target');
    })
</script>

Error:

overlay.js:17  Uncaught TypeError: Cannot read properties of undefined (reading 'find')
    at t.open (overlay.js:17:8117)
    at HTMLDocument.<anonymous> (lhb/:3251:19)

@yagnikvamja
Copy link
Member

Hello @ichenhua ,

The issue you are encountering is due to using the --prevent-on-load-init class in the <button> tag. This class is specifically intended to prevent the initialization of the modal when using public methods.

Note (for public methods only): To prevent initialization, you can add the --prevent-on-load-init class to the modal element before initializing it with new. To resolve the issue, you can remove this class as demonstrated in the example below:

<div id="modal-target" class="overlay modal overlay-open:opacity-100 modal-middle hidden" >
  <div class="modal-dialog overlay-open:opacity-100">
    <div class="modal-content">
      <div class="modal-header">
        <h3 class="modal-title">Dialog Title</h3>
        <button type="button" class="btn btn-text btn-circle btn-sm absolute end-3 top-3" aria-label="Close" data-overlay="#middle-center-modal" >
          <span class="icon-[tabler--x] size-4"></span>
        </button>
      </div>
      <div class="modal-body"> This is some placeholder content to show the scrolling behavior for modals. Instead of repeating the text in the modal, we use an inline style to set a minimum height, thereby extending the length of the overall modal and demonstrating the overflow scrolling. When content becomes longer than the height of the viewport, scrolling will move the modal as needed. </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-soft btn-secondary" data-overlay="#a" > Close </button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

<button id="open-btn" type="button" data-overlay="#modal-target" class="btn btn-primary" > Open modal using methods </button>
window.addEventListener("load", function () {
  const openBtn = document.querySelector("#open-btn");
  openBtn.addEventListener("click", () => {
    alert(111111);
    HSOverlay.open("#modal-target");
  });
});

By removing the --prevent-on-load-init class, the modal functionality should work as expected. If you have any further questions or concerns, please don’t hesitate to reach out!

@ichenhua
Copy link
Author

@yagnikvamja Thank you for patiently answering my questions. I have more three questions to ask.

1、I want to call a function that I have wrapped myself. How can I achieve this? The following methods are not effective.

<button id="open-btn" type="button" onclick="show()" class="btn btn-primary" > Open modal using methods </button>

function show(){
    HSOverlay.open("#modal-target");
}

2、Regarding the documentation, could you please provide some appropriate supplements?

For example, I want to call the modal component separately, but for beginners, with only the following explanation, they have no idea which JS file they should load.

overlays

Tailwind CSS Modal
A modal serves the purpose of presenting a dialog or box upon clicking a button.

[Require FlyonUI JS](https://flyonui.com/docs/getting-started/quick-start/)

3、Is there a suitable method to bundle the JS files loaded by the project into a single file?

For example, writing it like this makes the code look so ugly.

<script src="{{url_for('static', filename='plugins/tooltip.js')}}"></script>
<script src="{{url_for('static', filename='plugins/dropdown.js')}}"></script>
<script src="{{url_for('static', filename='plugins/overlay.js')}}"></script>

@ichenhua
Copy link
Author

@yagnikvamja Here's an additional question.

4、The jQuery core package referenced in the project is outdated, and the console shows warnings like this, which is very unhelpful.

JQMIGRATE: jQuery.trim is deprecated; use String.prototype.trim
overrideMethod @ hook.js:608
migrateWarn @ jquery-migrate.js:136
obj.<computed> @ jquery-migrate.js:170
$.cookie @ toolbar.js:2
init @ toolbar.js:104
(匿名) @ toolbar.js:188
mightThrow @ jquery.js:3489
process @ jquery.js:3557
setTimeout
(匿名) @ jquery.js:3602
fire @ jquery.js:3223
fireWith @ jquery.js:3353
fire @ jquery.js:3361
fire @ jquery.js:3223
fireWith @ jquery.js:3353
ready @ jquery.js:3844
completed @ jquery.js:3854
jquery-migrate.js:138 console.trace

@PruthviPraj00
Copy link
Member

PruthviPraj00 commented Dec 16, 2024

Hello @ichenhua,

I want to call a function that I have wrapped myself. How can I achieve this? The following methods are not effective.

  1. We have provided detailed documentation on how to use the modal's methods. Could you please clarify the specific functionality you're trying to achieve? We'd be happy to assist you further.

Regarding the documentation, could you please provide some appropriate supplements?

  1. Thank you for your valuable feedback. We will certainly address this issue and provide clearer guidance in a future release to help beginners better understand which JavaScript files need to be loaded.

Is there a suitable method to bundle the JS files loaded by the project into a single file?

  1. If you wish to include all FlyonUI components in your project, you can use the following script:
    <script src="../node_modules/flyonui/flyonui.js"></script>

The jQuery core package referenced in the project is outdated, and the console shows warnings like this, which is very unhelpful.

  1. Are you encountering the jQuery warnings when using the DataTables component?We have not faced this issue on our end, but please let us know if you would like assistance in resolving it.

@ichenhua
Copy link
Author

The first question is the most urgent, so let's focus on that first.
I saw the content of the document you mentioned, but I have a question.

<button id="modal-trigger" type="button" class="btn btn-primary --prevent-on-load-init" aria-haspopup="dialog" aria-expanded="false" aria-controls="modal-target" data-overlay="#modal-target" > Open modal </button>
<button id="open-btn" type="button" class="btn btn-primary">Open modal using methods</button>

const modal = new HSOverlay(document.querySelector('#modal-trigger'))
const openBtn = document.querySelector('#open-btn')

I hope that the second button, open-btn, triggers the modal. Why do we still need to use the first button querySelector('#modal-trigger')? Is the first button unnecessary?

How can I use just one button to trigger a modal window through a custom function?

@PruthviPraj00
Copy link
Member

Hello @ichenhua,

Why do we still need to use the first button with querySelector('#modal-trigger')? Is the first button unnecessary?

The reason we need both buttons is as follows:

<button id="modal-trigger" type="button" class="btn btn-primary --prevent-on-load-init" aria-haspopup="dialog" aria-expanded="false" aria-controls="modal-target" data-overlay="#modal-target" > Open modal </button>
<button id="open-btn" type="button" class="btn btn-primary">Open modal using methods</button>

The first button is required because of the data-overlay attribute, which is used to create the modal instance. This is the relevant code:

document.querySelectorAll('[data-overlay]:not(.--prevent-on-load-init)').forEach((el: HTMLElement) => {
      if (!window.$hsOverlayCollection.find(elC => (elC?.element?.el as HTMLElement) === el)) new HSOverlay(el)
}) 

How can I use just one button to trigger the modal window through a custom function?

You can use the basic modal button without needing to call any methods.

Can you please describe the scenario you are facing so we can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants