8000 fi(v-b-toggle): don't check for `evt.defaultPrevened` (closes #5391) … · bootstrap-vue/bootstrap-vue@a1543b2 · GitHub
[go: up one dir, main page]

Skip to content

Commit a1543b2

Browse files
authored
fi(v-b-toggle): don't check for evt.defaultPrevened (closes #5391) (#5396)
Co-authored-by: Jacob Müller
1 parent b701d73 commit a1543b2

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

src/directives/toggle/README.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,8 @@ trigger element when the target component is closed, and removed when open. As o
9393
## Preventing the target from opening or closing
9494

9595
To prevent the trigger element from toggling the target, set the `disabled` prop on `<button>`,
96-
`<b-button>`, or `<b-link>` and the toggle event will _not_ dispatched to the target(s).
97-
98-
`v-b-toggle` also checks if the `click` event (and `keydown` event for non-button/links) was
99-
canceled (i.e. via `event.preventDefault()` or `@click.prevent`), and if so, it will _not_ dispatch
100-
the toggle event to the target(s).
101-
102-
Because of this, avoid placing `v-b-toggle` on a `<b-button>` or `<b-link>` that has the `href` prop
103-
set to `'#'`, as these components (or components based on them) call `event.preventDefault()` to
104-
stop the browser from scrolling to the top of the page.
96+
`<b-button>`, or `<b-link>` (or components based on from `<b-link>`) and the toggle event will _not_
97+
dispatched to the target(s).
10598

10699
## Accessibility
107100

src/directives/toggle/toggle.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const EVENT_STATE_SYNC = 'bv::collapse::sync::state'
4949
// Private event we send to collapse to request state update sync event
5050
export const EVENT_STATE_REQUEST = 'bv::request::collapse::state'
5151

52-
const keyDownEvents = [ENTER, SPACE]
52+
const KEYDOWN_KEY_CODES = [ENTER, SPACE]
5353

5454
const RX_SPLIT_SEPARATOR = /\s+/
5555

@@ -86,9 +86,11 @@ const addClickListener = (el, vnode) => {
8686
removeClickListener(el)
8787
if (vnode.context) {
8888
const handler = evt => {
89-
const targets = el[BV_TOGGLE_TARGETS] || []
90-
const ignore = evt.type === 'keydown' && !arrayIncludes(keyDownEvents, evt.keyCode)
91-
if (!evt.defaultPrevented && !ignore && !isDisabled(el)) {
89+
if (
90+
!(evt.type === 'keydown' && !arrayIncludes(KEYDOWN_KEY_CODES, evt.keyCode)) &&
91+
!isDisabled(el)
92+
) {
93+
const targets = el[BV_TOGGLE_TARGETS] || []
9294
targets.forEach(target => {
9395
vnode.context.$root.$emit(EVENT_TOGGLE, target)
9496
})

0 commit comments

Comments
 (0)
0