Skip to content

Commit ed381f4

Browse files
fix(link): clear router-link/href collision and remove old link mixin (bootstrap-vue#1016)
* fix(link): don't use href for router-links * Merged dev into fix/link-router-to (bootstrap-vue#1018) * [carousel] Use dom utils * feat: dom utility methods (bootstrap-vue#1013) * feat: dom utility methods * Update index.js * [tooltip.js] Use dom utils * [dropdown.js] Use dom utils * [scrollspy.js] Use dom utils * feat: Use dom utils (bootstrap-vue#1017) * feat: dom utility methods * Update index.js * [tooltip.js] Use dom utils * [dropdown.js] Use dom utils * [scrollspy.js] Use dom utils * feat(array mixin): Add polyfill for Array.find for IE * [modal] use dom utils * [popover.vue] Use dom utils * [tooltip.vue] Use dom utils * fix: add fixes from PR bootstrap-vue#940 * fix: don't change href when disabled Previously, we we're altering the href to a "#" when disabled. Since we already handle disabling the link via click handlers, there is no reason to alter the semantics of the link. * Update toolpop.js * Update popover.vue * Update tooltip.vue * fix: typos * refactor: remove link mixin usage * fix(docs): proper component reference * fix: incorporate @pi0's typo fix
1 parent 3323531 commit ed381f4

File tree

9 files changed

+63
-104
lines changed

9 files changed

+63
-104
lines changed

docs/components/form-checkbox/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ semantic and accessible markup, so it is a solid replacement for the default che
66

77
**Advanced Breaking Change Warning:**
88
Major changes are coming to `<b-form-select>`, `<b-form-radio>`, `<b-form-checkbox>` that
9-
may alter how you use the components. These documents will be updatd as the changes are made.
10-
9+
may alter how you use the components. These documents will be updated as the changes are made.
1110

1211
**Example 1:** Single checkbox
1312
```html
@@ -96,7 +95,7 @@ export default {
9695
```
9796

9897
## Inline and Stacked checkboxes
99-
`<b-form-checbox>` components render as inline elements by default. Add a parent
98+
`<b-form-checkbox>` components render as inline elements by default. Add a parent
10099
with class `.custom-controls-stacked` to ensure each form control is on a separate line.
101100

102101
```html
@@ -144,17 +143,16 @@ Note that when `v-model` is bound to multiple checkboxes (i.e an array ref), the
144143
be returned in the `v-model` bound array. You should provide unique values for each
145144
checkbox's `value` prop.
146145

147-
148146
### Multiple checkboxes and accessibility
149147
When binding multiple checkboxes together, you should set the `name` prop to the same value for
150148
all checkboxes in the group, as well as wrap the group in a `<div>` (or other block element)
151-
which has the aria attribute `role="group"`. This will inform users of assitive technologies
149+
which has the aria attribute `role="group"`. This will inform users of assistive technologies
152150
that the checkboxes are related.
153151

154-
When placing the group of checkboxes inside a `<b-form-groupt>`, set a unique `id` on the
155-
element with `role="group"` and set the `label-for` prop of the `<b-form-fieldet>` to
152+
When placing the group of checkboxes inside a `<b-form-group>`, set a unique `id` on the
153+
element with `role="group"` and set the `label-for` prop of the `<b-form-group>` to
156154
this `id` value (see **Example 2** above). Whenever using grouped checkboxes, it is
157-
recommended that they be placed in a `<b-form-fieldset>` component to associate a `<label>`
155+
recommended that they be placed in a `<b-form-group>` component to associate a `<label>`
158156
with the entire group of checkboxes.
159157

160158

@@ -163,7 +161,7 @@ Render a checkbox with the look of a button by setting the prop `button`. Change
163161
setting the `button-variant` prop to one of the standard Bootstrap button variants (see
164162
[`<b-button>`](./button) for supported variants). The default `button-variant` is `secondary`.
165163

166-
Youy **must** wrap your button style checkbox(es) in a `<b-button-group>` component
164+
You **must** wrap your button style checkbox(es) in a `<b-button-group>` component
167165
and add the attribute `data-toggle="buttons"` to get the proper Bootstrap CSS styling.
168166

169167
Button style checkboxes will have the class `.active` automatically applied to the label
@@ -352,7 +350,7 @@ meaning in your application.
352350

353351

354352
## Non custom check inputs
355-
You can have `b-form-checkbox` render a browser native chechbox input by setting the `plain` prop.
353+
You can have `b-form-checkbox` render a browser native checkbox input by setting the `plain` prop.
356354

357355
**Note:** The `plain` prop has no effect with `button` is set.
358356

lib/components/link.js

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { assign, keys } from "../utils/object";
2+
import { arrayIncludes, concat } from "../utils/array";
23
import { mergeData } from "../utils";
34

45
/**
@@ -70,6 +71,34 @@ export function propsFactory() {
7071

7172
export const props = propsFactory();
7273

74+
export function pickLinkProps(propsToPick) {
75+
const freshLinkProps = propsFactory();
76+
// Normalize everything to array.
77+
propsToPick = concat(propsToPick);
78+
79+
return keys(freshLinkProps).reduce((memo, prop) => {
80+
if (arrayIncludes(propsToPick, prop)) {
81+
memo[prop] = freshLinkProps[prop];
82+
}
83+
84+
return memo;
85+
}, {});
86+
}
87+
88+
export function omitLinkProps(propsToOmit) {
89+
const freshLinkProps = propsFactory();
90+
// Normalize everything to array.
91+
propsToOmit = concat(propsToOmit);
92+
93+
return keys(props).reduce((memo, prop) => {
94+
if (!arrayIncludes(propsToOmit, prop)) {
95+
memo[prop] = freshLinkProps[prop];
96+
}
97+
98+
return memo;
99+
}, {});
100+
}
101+
73102
export const computed = {
74103
linkProps() {
75104
let linkProps = {},
@@ -85,18 +114,28 @@ export const computed = {
85114
}
86115
};
87116

88-
function computeTag(props) {
89-
return props.to && !props.disabled ? "router-link" : "a";
117+
function computeTag(props, parent) {
118+
return Boolean(parent.$router) && props.to && !props.disabled ? "router-link" : "a";
90119
}
91120

92-
function computeHref({ disabled, href, to }) {
93-
if (disabled) return "#";
121+
function computeHref({ disabled, href, to }, tag) {
122+
// We've already checked the parent.$router in computeTag,
123+
// so router-link means live router.
124+
// When deferring to Vue Router's router-link,
125+
// don't use the href attr at all.
126+
// Must return undefined for router-link to populate href.
127+
if (tag === "router-link") return void 0;
94128
// If href explicitly provided
95129
if (href) return href;
96-
// Fallback to `to` prop
97-
if (to && typeof to === "string") return to;
130+
// Reconstruct href when `to` used, but no router
131+
if (to) {
132+
// Fallback to `to` prop (if `to` is a string)
133+
if (typeof to === "string") return to;
134+
// Fallback to `to.path` prop (if `to` is an object)
135+
if (typeof to === "object" && typeof to.path === "string") return to.path;
136+
}
98137
// If nothing is provided use '#'
99-
return '#'
138+
return "#";
100139
}
101140

102141
function computeRel({ target, rel }) {
@@ -137,9 +176,9 @@ export default {
137176
functional: true,
138177
props: propsFactory(),
139178
render(h, { props, data, parent, children }) {
140-
const tag = computeTag(props),
179+
const tag = computeTag(props, parent),
141180
rel = computeRel(props),
142-
href = computeHref(props),
181+
href = computeHref(props, tag),
143182
eventType = tag === "router-link" ? "nativeOn" : "on",
144183
suppliedHandler = (data[eventType] || {}).click,
145184
handlers = { click: clickHandlerFactory({ tag, href, disabled: props.disabled, suppliedHandler, parent }) };

lib/components/pagination-nav.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@
120120
</style>
121121

122122
<script>
123-
import bLink from './link';
124-
import { pickLinkProps } from '../mixins/link';
123+
import bLink, { pickLinkProps } from './link';
125124
import { from as arrayFrom } from '../utils/array'
126125
import range from '../utils/range'
127126
import { assign } from '../utils/object';

lib/components/popover.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<script>
1010
import PopOver from '../classes/popover';
11+
import { warn } from '../utils';
1112
import { toolpopMixin } from '../mixins';
1213
1314
export default {
@@ -41,6 +42,7 @@
4142
this._toolpop = new PopOver(target, this.getConfig(), this.$root);
4243
} else {
4344
this._toolpop = null;
45+
warn("b-popover: 'target' element not found!");
4446
}
4547
return this._toolpop;
4648
}

lib/components/tooltip.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<script>
99
import ToolTip from '../classes/tooltip';
10+
import { warn } from '../utils';
1011
import { toolpopMixin } from '../mixins';
1112
1213
export default {
@@ -36,6 +37,7 @@
3637
this._toolpop = new ToolTip(target, this.getConfig(), this.$root);
3738
} else {
3839
this._toolpop = null;
40+
warn("b-tooltip: 'target' element not found!");
3941
}
4042
return this._toolpop;
4143
}

lib/mixins/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import formOptionsMixin from "./form-options";
88
import formSizeMixin from "./form-size";
99
import formStateMixin from "./form-state";
1010
import idMixin from "./id";
11-
import linkMixin from "./link";
1211
import listenOnRootMixin from "./listen-on-root";
1312
import toolpopMixin from "./toolpop";
1413

@@ -23,7 +22,6 @@ export {
2322
formSizeMixin,
2423
formStateMixin,
2524
idMixin,
26-
linkMixin,
2725
listenOnRootMixin,
2826
toolpopMixin
2927
};

lib/mixins/link.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

lib/mixins/toolpop.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { isArray } from '../utils/array';
66
import { assign } from '../utils/object';
77
import { isElement, getById } from '../utils/dom';
8-
import { observeDom, warn } from '../utils';
8+
import { observeDom } from '../utils';
99

1010
const PLACEMENTS = {
1111
top: 'top',
@@ -69,8 +69,6 @@ export default {
6969
attributeFilter: ['class', 'style']
7070
});
7171
}
72-
} else {
73-
warn("b-tooltip: 'target' element not found!");
7472
}
7573
});
7674
},

lib/utils/dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ dom.closest = function(selector, root) {
6767
};
6868

6969
dom.getById = function(id) {
70-
return document.getElementById(/^#/.test(id) ? id.slice(1) : id) || null;
70+
return document.getElementById(/^#/.test(id) ? id.slice(1) : id) || null;
7171
};
7272

7373
export const isElement = dom.isElement;

0 commit comments

Comments
 (0)