8000 Fix show/hide events and emits by xvaara · Pull Request #1821 · bootstrap-vue-next/bootstrap-vue-next · GitHub
[go: up one dir, main page]

Skip to content

Fix show/hide events and emits #1821

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

Merged
merged 27 commits into from
Nov 19, 2024

Conversation

xvaara
Copy link
Contributor
@xvaara xvaara commented Mar 20, 2024

fixes #1819

BEGIN_COMMIT_OVERRIDE
fix!: change all props starting skip or hide to start with no
feat(show/hide)!: make components that show/hide use a composable useShowHide
fix(show/hide): emit shown/hidden after transition
fix(show/hide): prevented emit events restore modelValue
feat(show/hide)!: add props lazy and unmount-lazy
fix(show/hide)!: many animation fixes
feat(show/hide): rename toggle prop to show, it opens the component with animation
feat(show/hide): add prop backdrop-first to animate backdrop first
feat(show/hide)!: add prop initial-animation to animate on initial render if modelValue is true, otherwise display the component without animation
feat(show/hide): add prop visible to show without animation
feat(BPopover): add hideMargin prop to add margin to the hide boundary
fix(BPopover): correctly calculate size on some edge cases
fix(BDropdown): correctly calculate size on some edge cases
fix(BPopover)!: change slot prop showState to visible
fix(BPopover): fire hide event only once
fix(BPopover): better hide functionality, called only once
fix(BPopover): Correct color arrow when arrow on top
fix(BPopover)!: remove prop persistent, use lazy instead
fix(BDropdown): focus returned to dropdown when escape key hit

BREAKING CHANGE: many changes to show/hide components (BCollapse,BDropdown,BModal,BOffcanvas,BPopover,BTooltip,BToast) and rename props starting with skip or hide to start with no
END_COMMIT_OVERRIDE

What kind of change does this PR introduce? (check at least one)

  • Bugfix 🐛 - fix(...)
  • Feature - feat(...)
  • ARIA accessibility - fix(...)
  • Documentation update - docs(...)
  • Other (please describe)

The PR fulfills these requirements:

  • Pull request title and all commits follow the Conventional Commits convention or has an override in this pull request body This is very important, as the CHANGELOG is generated from these messages, and determines the next version type. Pull requests that do not follow conventional commits or do not have an override will be denied

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@xvaara xvaara changed the title Fix show/hide events and emis Fix show/hide events and emits Mar 21, 2024
@VividLemon
Copy link
Member

@xvaara merge conflict detected 🤖

@xvaara xvaara force-pushed the fix-show-hide-events branch 2 times, most recently from 2a34de6 to 34b769a Compare April 17, 2024 01:31
@xvaara xvaara force-pushed the fix-show-hide-events branch from 5874926 to f6db490 Compare May 22, 2024 08:23
Copy link
Contributor
github-actions bot commented Jul 7, 2024

This PR is stale because it has been open for 45 days with no activity. It will not be auto-closed

@github-actions github-actions bot added the stale There has been no additional replies or questions and the thread is assumed closed label Jul 7, 2024
@xvaara xvaara added stale-exempt Use this to prevent auto-stalling of an issue and removed stale There has been no additional replies or questions and the thread is assumed closed labels Aug 30, 2024
@sebbayer
Copy link
sebbayer commented Sep 6, 2024

I think this PR needs an addition for BDropdown, where the shown Event is fired before the <ul> Element is positioned asynchronously by Floating UI. This leads to problems when e.g. trying to focus elements inside the dropdown right after opening it.

I would expect this to work similar to the shown.bs.dropdown Event of Dropdown in Bootstrap 5:

Fired when the dropdown has been made visible to the user and CSS transitions have completed.
Source: https://getbootstrap.com/docs/5.0/components/dropdowns/#events

As a solution idea, the useFloating composable returns an isPositioned boolean that could be used together with the open property: https://floating-ui.com/docs/vue#effects and we could wait for it to become true.

However this would require hiding and showing the <ul> only via v-if, not with v-show. I was thinking of opening a PR here, but implementing the isPositioned was problematic, altough it seems to be working as intended: floating-ui/floating-ui#3017

So maybe a simple setTimeout in BDropdown is an easier fix for this problem as well, but could sometimes not be sufficient.

In BPopover it is probably not an issue because a setTimeout is already applied before the shown Event is fired.

Copy link
pkg-pr-new bot commented Oct 11, 2024

Open in Stackblitz

pnpm add https://pkg.pr.new/bootstrap-vue-next/bootstrap-vue-next@1821
pnpm add https://pkg.pr.new/bootstrap-vue-next/bootstrap-vue-next/@bootstrap-vue-next/nuxt@1821

commit: ac69371

@xvaara xvaara requested a review from VividLemon October 11, 2024 17:03
@xvaara
Copy link
Contributor Author
xvaara commented Oct 11, 2024

@VividLemon this is mostly a test that everything works.. I'll cleanup this, and try to put the logic in a composable.

@xvaara
Copy link
Contributor Author
xvaara commented Oct 22, 2024

@@ -79,7 +79,7 @@ export default {
description:
'Specify the number of pixels to shift the menu by. See above for details.',
},
skipWrapper: {
noWrapper: {
Copy link
Member

Choose a reason for hiding this comment

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

Why have we changed hide or skip to no

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Imho. they should be consistent. Hide isn't really hiding it, skip is a weird word I added to props at some point... All of them should be just noFoo, since it's clear that you are removing/blocking something.

I'm not gonna die on this hill, so if you're against these changes I'll roll them back.

@dwgray
Copy link
Member
dwgray commented Nov 11, 2024

I don't see an obvious way to address this, but the generated HTML is considerably more verbose, even when lazy=true. This is most obvious with tooltips, where there might be a large number of them on a page. I don't think this blocks anything, but if there is a reasonable way to pair down the generated HTML on lazy=true that would be great.

Taking the following vue template fragment, the generated code (before expansion) goes from 111 characters to 609 characters:

<span id="tip-test">Testing a tooltip
    <BTooltip target="tip-test" triggers="hover click blur" title="This is a test" lazy />
</span>

The code before looked like this:

<span id="tip-test">Testing a tooltip <span id="___BVN__ID__v-7__popover____placeholder"></span><!----></span>

Now it looks like this:

<span id="tip-test">Testing a tooltip <span data-v-e55cd8ec=""
        id="___BVN__ID__v-7__popover____placeholder"></span><!--teleport start-->
    <div data-v-e55cd8ec="" id="___BVN__ID__v-7__popover___" triggers="hover click blur"
        class="tooltip b-tooltip fade  bs-tooltip-top" role="tooltip" tabindex="-1"
        style="position: absolute; left: 0px; top: 0px; display: none; transform: translate(68.48px, 69.12px); will-change: transform;">
        <div data-v-e55cd8ec="" class="tooltip-arrow" data-popper-arrow="" style="position: absolute;"></div><!---->
    </div><!--teleport end-->
</span>

For completeness:
Before, expanded:

span id="tip-test">Testing a tooltip <span id="___BVN__ID__v-7__popover____placeholder"></span>
    <div id="___BVN__ID__v-7__popover___" triggers="hover click blur" lazy=""
        class="tooltip b-tooltip show fade  bs-tooltip-top" role="tooltip" tabindex="-1"
        style="position: absolute; left: 0px; top: 0px; transform: translate(23.04px, 40.32px); will-change: transform;">
        <div class="tooltip-arrow" data-popper-arrow="" style="position: absolute; left: 39.1px;"></div>
        <div class="overflow-auto" style="max-height: 69.28px; max-width: 1619.84px;">
            <div class="position-sticky top-0 tooltip-inner">This is a test</div><!---->
        </div>
    </div>
</span>

After, expanded:

<span id="tip-test">Testing a tooltip <span data-v-e55cd8ec=""
        id="___BVN__ID__v-7__popover____placeholder"></span><!--teleport start-->
    <div data-v-e55cd8ec="" id="___BVN__ID__v-7__popover___" triggers="hover click blur"
        class="tooltip b-tooltip fade bs-tooltip-top" role="tooltip" tabindex="-1"
        style="position: absolute; left: 0px; top: 0px; transform: translate(68.48px, 69.12px); will-change: transform; display: none;">
        <div data-v-e55cd8ec="" class="tooltip-arrow" data-popper-arrow="" style="position: absolute;"></div>
        <div data-v-e55cd8ec="" class="overflow-auto" style="max-height: 69.28px; max-width: 1619.84px;">
            <div data-v-e55cd8ec="" class="position-sticky top-0 tooltip-inner">This is a test</div><!---->
        </div>
    </div><!--teleport end-->
</span>

@xvaara xvaara force-pushed the fix-show-hide-events branch from ca774d4 to b11a36e Compare November 13, 2024 08:26
@xvaara xvaara marked this pull request as ready for review November 13, 2024 22:47
@xvaara xvaara requested a review from VividLemon November 13, 2024 22:58
@VividLemon
Copy link
Member

Waiting on this for #2346 release. Lmk when it's done

@xvaara
Copy link
Contributor Author
xvaara commented Nov 19, 2024

It was ready, that's why I asked for the review.

@xvaara xvaara force-pushed the fix-show-hide-events branch from 2285086 to e386700 Compare November 19, 2024 14:18
@xvaara xvaara merged commit 673529d into bootstrap-vue-next:main Nov 19, 2024
4 checks passed
xvaara added a commit to xvaara/bootstrap-vue-next that referenced this pull request Nov 19, 2024
* upstream/main: (49 commits)
  fix: rename ref to avoid Vue warnings (Fix bootstrap-vue-next#2337) (bootstrap-vue-next#2353)
  Fix show/hide events and emits (bootstrap-vue-next#1821)
  add some classes and ids for components (bootstrap-vue-next#2344)
  feat: add __usedComponents __usedDirectives property to the BootstrapVueNextResolver function (bootstrap-vue-next#2351)
  doc(BNavbar): Parity pass (bootstrap-vue-next#2347)
  docs: fix lint error (bootstrap-vue-next#2349)
  fix(BNavbarToggle): toggle default slot doesnt have a scoped argument 'expanded' fixes bootstrap-vue-next#2348
  feat!: remove html props -- use equivalent slots fixes bootstrap-vue-next#1930 (bootstrap-vue-next#2311)
  chore: release main (bootstrap-vue-next#2343)
  fix(BDropdown): fix infinite loop on keyboard navigation (bootstrap-vue-next#2342)
  chore: release main (bootstrap-vue-next#2336)
  feat(BPagination): add keyboard shortcuts fixes bootstrap-vue-next#2153
  doc(BNav): Parity pass (bootstrap-vue-next#2332)
  chore: release main (bootstrap-vue-next#2327)
  fix(BTable): dynamic slots not rendering fixes bootstrap-vue-next#2328 (bootstrap-vue-next#2329)
  feat(BTable): make it possible to style custom footers (bootstrap-vue-next#2314)
  chore: release main (bootstrap-vue-next#2323)
  fix(BFormGroup): fix layout problem when label-for is not used (bootstrap-vue-next#2321)
  chore: release main (bootstrap-vue-next#2320)
  feat(BPagination): add small screen support (bootstrap-vue-next#2308)
  ...
@VividLemon
Copy link
Member

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale-exempt Use this to prevent auto-stalling of an issue
Projects
None yet
4 participants
0