🌐 AI搜索 & 代理 主页
Skip to content

Commit c11c237

Browse files
authored
feat(b-sidebar): add noEnforceFocus prop (closes #5707) (#5734)
* Update readme.md * update sidebar.js * update package.json
1 parent 2c48020 commit c11c237

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/components/sidebar/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ When the sidebar is opened, the entire sidebar will receive focus, which is desi
371371
reader and keyboard-only users. When the sidebar is closed, the element that previously had focus
372372
before the sidebar was opened will be re-focused.
373373

374+
In some circumstances, you may need to disable the enforce focus feature completely. You can do this
375+
by setting the prop `no-enforce-focus`, although this is generally discouraged for accessibility
376+
reasons.
377+
374378
When the sidebar is open, users can press <kbd>Esc</kbd> to close the sidebar. To disable this
375379
feature, set the `no-close-on-esc` prop to `true`. with the backdrop enabled, you can use the prop
376380
`no-close-on-backdrop` to disable the close on backdrop click feature.

src/components/sidebar/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
{
105105
"prop": "noCloseOnRouteChange",
106106
"description": "When set to `true`, disables closing of the sidebar on route change"
107+
},
108+
{
109+
"prop": "noEnforceFocus",
110+
"version": "2.17.0",
111+
"description": "Disables the enforce focus routine which maintains focus inside the sidebar"
107112
}
108113
],
109114
"events": [

src/components/sidebar/sidebar.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ export const BSidebar = /*#__PURE__*/ Vue.extend({
234234
type: Boolean,
235235
default: false
236236
},
237+
noEnforceFocus: {
238+
type: Boolean,
239+
default: false
240+
},
237241
lazy: {
238242
type: Boolean,
239243
default: false
@@ -369,12 +373,12 @@ export const BSidebar = /*#__PURE__*/ Vue.extend({
369373
/* istanbul ignore next */
370374
onTopTrapFocus() /* istanbul ignore next */ {
371375
const tabables = getTabables(this.$refs.content)
372-
attemptFocus(tabables.reverse()[0])
376+
this.enforceFocus(tabables.reverse()[0])
373377
},
374378
/* istanbul ignore next */
375379
onBottomTrapFocus() /* istanbul ignore next */ {
376380
const tabables = getTabables(this.$refs.content)
377-
attemptFocus(tabables[0])
381+
this.enforceFocus(tabables[0])
378382
},
379383
onBeforeEnter() {
380384
// Returning focus to `document.body` may cause unwanted scrolls,
@@ -385,16 +389,21 @@ export const BSidebar = /*#__PURE__*/ Vue.extend({
385389
},
386390
onAfterEnter(el) {
387391
if (!contains(el, getActiveElement())) {
388-
attemptFocus(el)
392+
this.enforceFocus(el)
389393
}
390394
this.$emit('shown')
391395
},
392396
onAfterLeave() {
393-
attemptFocus(this.$_returnFocusEl)
397+
this.enforceFocus(this.$_returnFocusEl)
394398
this.$_returnFocusEl = null
395399
// Trigger lazy render
396400
this.isOpen = false
397401
this.$emit('hidden')
402+
},
403+
enforceFocus(el) {
404+
if (!this.noEnforceFocus) {
405+
attemptFocus(el)
406+
}
398407
}
399408
},
400409
render(h) {

0 commit comments

Comments
 (0)