@@ -28,7 +28,9 @@ const propTypes = {
2828 isFixedWidth : PropTypes . bool ,
2929 children : PropTypes . node ,
3030 backgroundColor : PropTypes . string ,
31- notEnabled : PropTypes . bool
31+ notEnabled : PropTypes . bool ,
32+ buttonClassNames : PropTypes . string ,
33+ pickerListClassNames : PropTypes . string
3234} ;
3335
3436const defaultSort = ( a , b , selectedOption ) => {
@@ -52,7 +54,9 @@ const Picker = ({
5254 children,
5355 dropdownDirection = 'right' ,
5456 backgroundColor = '#1a4480' ,
55- notEnabled
57+ notEnabled,
58+ buttonClassNames = "" ,
59+ pickerListClassNames = ""
5660} ) => {
5761 const pickerRef = useRef ( null ) ;
5862 const buttonRef = useRef ( null ) ;
@@ -97,11 +101,11 @@ const Picker = ({
97101 useEffect ( ( ) => {
98102 const closeMenu = ( e ) => {
99103 if ( (
100- expanded &&
101- pickerRef . current &&
102- ! pickerRef . current . contains ( e . target ) &&
103- e . target . id !== `${ id } -${ fontAwesomeIconId } ` &&
104- e . target . parentNode . id !== `${ id } -${ fontAwesomeIconId } `
104+ expanded
105+ && pickerRef . current
106+ && ! pickerRef . current . contains ( e . target )
107+ && e . target . id !== `${ id } -${ fontAwesomeIconId } `
108+ && e . target . parentNode . id !== `${ id } -${ fontAwesomeIconId } `
105109 ) ) {
106110 setExpanded ( false ) ;
107111 }
@@ -149,39 +153,40 @@ const Picker = ({
149153 } ;
150154
151155 return (
152- < div id = { id } className = { `usa-dt-picker ${ className } ` } ref = { pickerRef } style = { { backgroundColor : backgroundColor } } >
153- < div className = "usa-dt-picker__dropdown-container" style = { { backgroundColor : backgroundColor } } >
156+ < div id = { id } className = { `usa-dt-picker ${ className } ` } ref = { pickerRef } style = { { backgroundColor } } >
157+ < div className = "usa-dt-picker__dropdown-container" style = { { backgroundColor } } >
154158 < button
155- style = { { backgroundColor : backgroundColor } }
159+ style = { { backgroundColor } }
156160 ref = { buttonRef }
161+ type = "button"
157162 aria-label = "Dropdown Toggle Button"
158- className = " usa-dt-picker__button"
163+ className = { ` usa-dt-picker__button ${ buttonClassNames } ` }
159164 onClick = { toggleMenu } >
160165
161166 { icon && (
162- < div className = "usa-dt-picker__icon" >
167+ < div className = "usa-dt-picker__icon" >
163168 { icon }
164169 </ div >
165170 ) }
166171
167- { children ?
168- < > { children } </ > :
169- < >
170- < span className = "usa-dt-picker__button-text" style = { { backgroundColor : backgroundColor } } >
171- { selectedOption }
172- </ span >
173- < span className = "usa-dt-picker__button-icon" >
174- { ! expanded && (
175- < FontAwesomeIcon id = { `${ id } -${ fontAwesomeIconId } ` } icon = "chevron-down" alt = "Toggle menu" color = "#555" />
176- ) }
177- { expanded && (
178- < FontAwesomeIcon id = { `${ id } -${ fontAwesomeIconId } ` } icon = "chevron-up" alt = "Toggle menu" color = "#555" />
179- ) }
180- </ span >
181- </ >
182- }
172+ { children
173+ || (
174+ < >
175+ < span className = "usa-dt-picker__button-text" style = { { backgroundColor } } >
176+ { selectedOption }
177+ </ span >
178+ < span className = "usa-dt-picker__button-icon" >
179+ { ! expanded && (
180+ < FontAwesomeIcon id = { `${ id } -${ fontAwesomeIconId } ` } icon = "chevron-down" alt = "Toggle menu" color = "#555" />
181+ ) }
182+ { expanded && (
183+ < FontAwesomeIcon id = { `${ id } -${ fontAwesomeIconId } ` } icon = "chevron-up" alt = "Toggle menu" color = "#555" />
184+ ) }
185+ </ span >
186+ </ >
187+ ) }
183188 </ button >
184- < ul className = { `usa-dt-picker__list ${ expanded ? '' : 'hide' } ` } style = { getDropdownListStyles ( ) } >
189+ < ul className = { `usa-dt-picker__list ${ pickerListClassNames } ${ expanded ? '' : 'hide' } ` } style = { getDropdownListStyles ( ) } >
185190 { options
186191 . sort ( handleSort )
187192 . map ( ( option ) => ( {
@@ -192,6 +197,7 @@ const Picker = ({
192197 < li key = { uniqueId ( ) } className = { `usa-dt-picker__list-item ${ option ?. classNames ? option . classNames : '' } ` } >
193198 < button
194199 className = { `usa-dt-picker__item ${ option . name === selectedOption ? 'active' : '' } ` }
200+ type = "button"
195201 value = { `${ option . value || option . name } ` }
196202 onClick = { ( e ) => {
197203 e . preventDefault ( ) ;
@@ -205,8 +211,7 @@ const Picker = ({
205211 { option . component ? option . component : option . name }
206212 </ button >
207213 </ li >
208- ) )
209- }
214+ ) ) }
210215 </ ul >
211216 </ div >
212217 </ div >
0 commit comments