🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/directives/toggle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,8 @@ trigger element when the target component is closed, and removed when open. As o
## Preventing the target from opening or closing

To prevent the trigger element from toggling the target, set the `disabled` prop on `<button>`,
`<b-button>`, or `<b-link>` and the toggle event will _not_ dispatched to the target(s).

`v-b-toggle` also checks if the `click` event (and `keydown` event for non-button/links) was
canceled (i.e. via `event.preventDefault()` or `@click.prevent`), and if so, it will _not_ dispatch
the toggle event to the target(s).

Because of this, avoid placing `v-b-toggle` on a `<b-button>` or `<b-link>` that has the `href` prop
set to `'#'`, as these components (or components based on them) call `event.preventDefault()` to
stop the browser from scrolling to the top of the page.
`<b-button>`, or `<b-link>` (or components based on from `<b-link>`) and the toggle event will _not_
dispatched to the target(s).

## Accessibility

Expand Down
10 changes: 6 additions & 4 deletions src/directives/toggle/toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const EVENT_STATE_SYNC = 'bv::collapse::sync::state'
// Private event we send to collapse to request state update sync event
export const EVENT_STATE_REQUEST = 'bv::request::collapse::state'

const keyDownEvents = [ENTER, SPACE]
const KEYDOWN_KEY_CODES = [ENTER, SPACE]

const RX_SPLIT_SEPARATOR = /\s+/

Expand Down Expand Up @@ -86,9 +86,11 @@ const addClickListener = (el, vnode) => {
removeClickListener(el)
if (vnode.context) {
const handler = evt => {
const targets = el[BV_TOGGLE_TARGETS] || []
const ignore = evt.type === 'keydown' && !arrayIncludes(keyDownEvents, evt.keyCode)
if (!evt.defaultPrevented && !ignore && !isDisabled(el)) {
if (
!(evt.type === 'keydown' && !arrayIncludes(KEYDOWN_KEY_CODES, evt.keyCode)) &&
!isDisabled(el)
) {
const targets = el[BV_TOGGLE_TARGETS] || []
targets.forEach(target => {
vnode.context.$root.$emit(EVENT_TOGGLE, target)
})
Expand Down