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

Add fomantic-dropdown webcomponent #33723

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

McRaeAlex
Copy link
Contributor

@McRaeAlex McRaeAlex commented Feb 25, 2025

Closes #33532

Using a vanilla web component add the correct event listener for handling dropdowns.

Screen.Recording.2025-02-25.at.1.38.41.PM.mov

Using a vanilla web component add the correct event listener for
handling dropdowns.
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 25, 2025
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 25, 2025
@github-actions github-actions bot added modifies/templates This PR modifies the template files modifies/frontend labels Feb 25, 2025
@McRaeAlex McRaeAlex marked this pull request as ready for review February 25, 2025 21:41
Copy link
Member

@delvh delvh left a comment

Choose a reason for hiding this comment

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

Pity to see more jQuery usage, but I know that there is no way around that for now

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Feb 25, 2025
@silverwind
Copy link
Member

I see the size of the webpack chunk did not change, which means webpack is not bundling anything extra into that chunk:

asset js/webcomponents.js 87.9 KiB

So I guess this is more like a convenience-only thing right now.

@lunny
Copy link
Member

lunny commented Feb 25, 2025

What's the long-term plan for the new component? Will it be applied to all other menus? Maybe it's a placeholder for a rewritten, so that we can have a name without related to fomantic-ui.

@McRaeAlex
Copy link
Contributor Author

@lunny @silverwind Right now this is a small wrapper to ensure event listeners are correctly added. This enabled the use of dropdowns in both vuejs and when dynamically added to pages without manually adding the $(el).dropdown() call.

Longer term I would like to work with you to figure out a roadmap for #29849 which would eventually replace this code. For example I tried out shoelace.style for this and it seems promising but limiting in the ability to style it.

@wxiaoguang
Copy link
Contributor

Sorry, we can't do that.

The dropdown is quite special, we already have a complex system to init various dropdowns correctly. This approach

    if (window.jQuery) {
      window.$(this).dropdown();
    }

will definitely break.

@wxiaoguang
Copy link
Contributor

The real problem is in onShowMoreFiles, it forgets to init the dropdowns (and maybe other elements).

The proper fix is to init necessary elements in onShowMoreFiles, but not using the fragile webcomopnent.

image

Copy link
Contributor

@wxiaoguang wxiaoguang left a comment

Choose a reason for hiding this comment

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

Need to call init functions instead of using webcomponent

For example: initCompReactionSelector and others.

Webcomponent won't help too much for our case. At the moment, the best approach I can think of is: #33498 (comment)


<button data-global-click="show-panel"></button>
<a data-global-click="link-acton"></a>
<div class="dropdown" data-global-init="initMyDropdown"></div>
<div class="editor" data-global-init="initComboMarkdownDropdown"></div>
<input name="avatar" data-global-init="initAvatarUploaderWithCropper">

Then we could resolve many longstanding problems:

  1. avoid many duplicate "init" calls
  2. incorrect init & double init (especially when use htmx or partial reloading)

@GiteaBot GiteaBot added lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Feb 26, 2025
@McRaeAlex
Copy link
Contributor Author

Sorry, we can't do that.

The dropdown is quite special, we already have a complex system to init various dropdowns correctly. This approach

    if (window.jQuery) {
      window.$(this).dropdown();
    }

will definitely break.

Can you explain why you believe this code is fragile?

Need to call init functions instead of using webcomponent

For example: initCompReactionSelector and others.

I don't see why #33498 (comment) is better than wrapping that init call into a web component for example <combo-markdown-dropdown class="editor" />.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/blocked A maintainer has reservations with the PR and thus it cannot be merged modifies/frontend modifies/templates This PR modifies the template files size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Comments on dynamically added content do not work
6 participants