1- import { cloneVNode , defineComponent , h , inject , onMounted , PropType , Ref , ref } from 'vue'
1+ import { cloneVNode , computed , defineComponent , h , inject , onMounted , PropType , Ref , ref } from 'vue'
22
33import { CButton } from '../button'
44
@@ -8,10 +8,6 @@ import type { Triggers } from '../../types'
88const CDropdownToggle = defineComponent ( {
99 name : 'CDropdownToggle' ,
1010 props : {
11- /**
12- * Toggle the active state for the component.
13- */
14- active : Boolean ,
1511 /**
1612 * Sets the color context of the component to one of CoreUI’s themed colors.
1713 *
@@ -40,6 +36,15 @@ const CDropdownToggle = defineComponent({
4036 * Toggle the disabled state for the component.
4137 */
4238 disabled : Boolean ,
39+ /**
40+ * If a dropdown `variant` is set to `nav-item` then render the toggler as a link instead of a button.
41+ *
42+ * @since v5.0.0-alpha.1
43+ */
44+ navLink : {
45+ type : Boolean ,
46+ default : true ,
47+ } ,
4348 /**
4449 * @values 'rounded', 'rounded-top', 'rounded-end', 'rounded-bottom', 'rounded-start', 'rounded-circle', 'rounded-pill', 'rounded-0', 'rounded-1', 'rounded-2', 'rounded-3'
4550 */
@@ -87,18 +92,10 @@ const CDropdownToggle = defineComponent({
8792 const visible = inject ( 'visible' ) as Ref < boolean >
8893 const setVisible = inject ( 'setVisible' ) as ( _visible ?: boolean ) => void
8994
90- const className = [
91- {
92- 'dropdown-toggle' : props . caret ,
93- 'dropdown-toggle-split' : props . split ,
94- active : props . active ,
95- disabled : props . disabled ,
96- } ,
97- ]
98-
9995 const triggers = {
10096 ...( ( props . trigger === 'click' || props . trigger . includes ( 'click' ) ) && {
101- onClick : ( ) => {
97+ onClick : ( event : Event ) => {
98+ event . preventDefault ( )
10299 if ( props . disabled ) {
103100 return
104101 }
@@ -123,6 +120,20 @@ const CDropdownToggle = defineComponent({
123120 } ) ,
124121 }
125122
123+ const togglerProps = computed ( ( ) => {
124+ return {
125+ class : {
126+ 'nav-link' : dropdownVariant === 'nav-item' && props . navLink ,
127+ 'dropdown-toggle' : props . caret ,
128+ 'dropdown-toggle-split' : props . split ,
129+ disabled : props . disabled ,
130+ show : visible . value
131+ } ,
132+ 'aria-expanded' : visible . value ,
133+ ...( ! props . disabled && { ...triggers } ) ,
134+ }
135+ } )
136+
126137 onMounted ( ( ) => {
127138 if ( togglerRef . value ) {
128139 dropdownToggleRef . value = togglerRef . value . $el
@@ -140,45 +151,30 @@ const CDropdownToggle = defineComponent({
140151 ...triggers ,
141152 } ) ,
142153 )
143- : dropdownVariant === 'nav-item'
154+ : dropdownVariant === 'nav-item' && props . navLink
144155 ? h (
145156 'a' ,
146157 {
147- active : props . active ,
148- class : [
149- 'nav-link' ,
150- className ,
151- {
152- show : visible . value ,
153- } ,
154- ] ,
155- disabled : props . disabled ,
156158 href : '#' ,
159+ ...togglerProps . value ,
160+ role : 'button' ,
157161 ref : dropdownToggleRef ,
158- ...triggers ,
159162 } ,
160163 { default : ( ) => slots . default && slots . default ( ) } ,
161164 )
162165 : h (
163166 CButton ,
164167 {
165- class : [
166- className ,
167- {
168- show : visible . value ,
169- } ,
170- ] ,
171- active : props . active ,
168+ ...togglerProps . value ,
172169 color : props . color ,
170+ component : props . component ,
173171 disabled : props . disabled ,
174- ref : ( el ) => {
175- togglerRef . value = el
176- } ,
177172 shape : props . shape ,
178173 size : props . size ,
179- ...triggers ,
180- ...( props . component === 'button' && { type : 'button' } ) ,
181174 variant : props . variant ,
175+ ref : ( el ) => {
176+ togglerRef . value = el
177+ } ,
182178 } ,
183179 ( ) =>
184180 props . split
0 commit comments