Skip to content

Commit 4586b49

Browse files
authored
fix(b-icon): local component lookup (#5939)
1 parent 8a367b6 commit 4586b49

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/icons/icon.js

+15-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import { pascalCase, trim } from '../utils/string'
55
import { BIconBlank } from './icons'
66
import { commonIconProps } from './helpers/icon-base'
77

8+
const findIconComponent = (ctx, iconName) => {
9+
if (!ctx) {
10+
return null
11+
}
12+
const components = (ctx.$options || {}).components
13+
const iconComponent = components[iconName]
14+
return iconComponent || findIconComponent(ctx.$parent, iconName)
15+
}
16+
817
// Helper BIcon component
918
// Requires the requested icon component to be installed
1019
export const BIcon = /*#__PURE__*/ Vue.extend({
@@ -23,13 +32,13 @@ export const BIcon = /*#__PURE__*/ Vue.extend({
2332
},
2433
render(h, { data, props, parent }) {
2534
const icon = pascalCase(trim(props.icon || '')).replace(RX_ICON_PREFIX, '')
26-
const iconName = `BIcon${icon}`
35+
2736
// If parent context exists, we check to see if the icon has been registered
28-
// Either locally in the parent component, or globally at the `$root` level
37+
// either locally in the parent component, or globally at the `$root` level
2938
// If not registered, we render a blank icon
30-
const components = ((parent || {}).$options || {}).components
31-
const componentRefOrName =
32-
icon && components ? components[iconName] || BIconBlank : icon ? iconName : BIconBlank
33-
return h(componentRefOrName, mergeData(data, { props: { ...props, icon: null } }))
39+
return h(
40+
icon ? findIconComponent(parent, `BIcon${icon}`) || BIconBlank : BIconBlank,
41+
mergeData(data, { props: { ...props, icon: null } })
42+
)
3443
}
3544
})

0 commit comments

Comments
 (0)