@@ -6,6 +6,7 @@ import { getComponentConfig } from '../../utils/config'
66import { addClass , removeClass } from '../../utils/dom'
77import { isBoolean , isEvent , isFunction } from '../../utils/inspect'
88import { keys } from '../../utils/object'
9+ import { toString } from '../../utils/string'
910import { BLink , propsFactory as linkPropsFactory } from '../link/link'
1011
1112// --- Constants --
@@ -62,6 +63,9 @@ export const props = { ...linkProps, ...btnProps }
6263
6364// --- Helper methods ---
6465
66+ // Returns true if a tag's name is name
67+ const tagIs = ( tag , name ) => toString ( tag ) . toLowerCase ( ) === toString ( name ) . toLowerCase ( )
68+
6569// Focus handler for toggle buttons. Needs class of 'focus' when focused.
6670const handleFocus = evt => {
6771 if ( evt . type === 'focusin' ) {
@@ -72,23 +76,14 @@ const handleFocus = evt => {
7276}
7377
7478// Is the requested button a link?
75- const isLink = props => {
76- // If tag prop is set to `a`, we use a b-link to get proper disabled handling
77- return Boolean ( props . href || props . to || ( props . tag && String ( props . tag ) . toLowerCase ( ) === 'a' ) )
78- }
79+ // If tag prop is set to `a`, we use a b-link to get proper disabled handling
80+ const isLink = props => props . href || props . to || tagIs ( props . tag , 'a' )
7981
8082// Is the button to be a toggle button?
8183const isToggle = props => isBoolean ( props . pressed )
8284
8385// Is the button "really" a button?
84- const isButton = props => {
85- if ( isLink ( props ) ) {
86- return false
87- } else if ( props . tag && String ( props . tag ) . toLowerCase ( ) !== 'button' ) {
88- return false
89- }
90- return true
91- }
86+ const isButton = props => ! ( isLink ( props ) || ( props . tag && ! tagIs ( props . tag , 'button' ) ) )
9287
9388// Is the requested tag not a button or link?
9489const isNonStandardTag = props => ! isLink ( props ) && ! isButton ( props )
@@ -97,7 +92,7 @@ const isNonStandardTag = props => !isLink(props) && !isButton(props)
9792const computeClass = props => [
9893 `btn-${ props . variant || getComponentConfig ( NAME , 'variant' ) } ` ,
9994 {
100- [ `btn-${ props . size } ` ] : Boolean ( props . size ) ,
95+ [ `btn-${ props . size } ` ] : props . size ,
10196 'btn-block' : props . block ,
10297 'rounded-pill' : props . pill ,
10398 'rounded-0' : props . squared && ! props . pill ,
0 commit comments