@@ -18,6 +18,7 @@ import TreeManager from './tree-manager'
1818import keyboardNavigation from './tree-manager/keyboardNavigation'
1919
2020import styles from './index.css'
21+ import { getAriaLabel } from './a11y'
2122
2223const cx = cn . bind ( styles )
2324
@@ -34,8 +35,7 @@ class DropdownTreeSelect extends Component {
3435 label : PropTypes . string ,
3536 labelRemove : PropTypes . string ,
3637 } ) ,
37- showDropdown : PropTypes . bool ,
38- showDropdownAlways : PropTypes . bool ,
38+ showDropdown : PropTypes . oneOf ( [ 'default' , 'initial' , 'always' ] ) ,
3939 className : PropTypes . string ,
4040 onChange : PropTypes . func ,
4141 onAction : PropTypes . func ,
@@ -54,19 +54,19 @@ class DropdownTreeSelect extends Component {
5454 onBlur : ( ) => { } ,
5555 onChange : ( ) => { } ,
5656 texts : { } ,
57+ showDropdown : 'default' ,
5758 }
5859
5960 constructor ( props ) {
6061 super ( props )
6162 this . state = {
62- showDropdown : this . props . showDropdown || this . props . showDropdownAlways || false ,
6363 searchModeOn : false ,
6464 currentFocus : undefined ,
6565 }
6666 this . clientId = props . id || clientIdGenerator . get ( this )
6767 }
6868
69- initNewProps = ( { data, mode, showPartiallySelected } ) => {
69+ initNewProps = ( { data, mode, showDropdown , showPartiallySelected } ) => {
7070 this . treeManager = new TreeManager ( {
7171 data,
7272 mode,
@@ -78,7 +78,10 @@ class DropdownTreeSelect extends Component {
7878 if ( currentFocusNode ) {
7979 currentFocusNode . _focused = true
8080 }
81- this . setState ( this . treeManager . getTreeAndTags ( ) )
81+ this . setState ( {
82+ showDropdown : / i n i t i a l | a l w a y s / . test ( showDropdown ) || false ,
83+ ...this . treeManager . getTreeAndTags ( ) ,
84+ } )
8285 }
8386
8487 resetSearchState = ( ) => {
@@ -92,8 +95,7 @@ class DropdownTreeSelect extends Component {
9295 }
9396
9497 componentWillMount ( ) {
95- const { data, mode, showPartiallySelected } = this . props
96- this . initNewProps ( { data, mode, showPartiallySelected } )
98+ this . initNewProps ( this . props )
9799 }
98100
99101 componentWillUnmount ( ) {
@@ -107,7 +109,7 @@ class DropdownTreeSelect extends Component {
107109 handleClick = ( e , callback ) => {
108110 this . setState ( prevState => {
109111 // keep dropdown active when typing in search box
110- const showDropdown = this . props . showDropdownAlways || this . keepDropdownActive || ! prevState . showDropdown
112+ const showDropdown = this . props . showDropdown === 'always' || this . keepDropdownActive || ! prevState . showDropdown
111113
112114 // register event listeners only if there is a state change
113115 if ( showDropdown !== prevState . showDropdown ) {
@@ -126,7 +128,7 @@ class DropdownTreeSelect extends Component {
126128 }
127129
128130 handleOutsideClick = e => {
129- if ( this . props . showDropdownAlways || ! isOutsideClick ( e , this . node ) ) {
131+ if ( this . props . showDropdown === 'always' || ! isOutsideClick ( e , this . node ) ) {
130132 return
131133 }
132134
@@ -260,6 +262,17 @@ class DropdownTreeSelect extends Component {
260262 e . preventDefault ( )
261263 }
262264
265+ getAriaAttributes = ( ) => {
266+ const { mode, texts } = this . props
267+
268+ if ( mode !== 'radioSelect' ) return { }
269+
270+ return {
271+ role : 'radiogroup' ,
272+ ...getAriaLabel ( texts . label ) ,
273+ }
274+ }
275+
263276 render ( ) {
264277 const { disabled, readOnly, mode, texts } = this . props
265278 const { showDropdown, currentFocus } = this . state
@@ -298,7 +311,7 @@ class DropdownTreeSelect extends Component {
298311 />
299312 </ Trigger >
300313 { showDropdown && (
301- < div className = "dropdown-content" >
314+ < div className = "dropdown-content" { ... this . getAriaAttributes ( ) } >
302315 { this . state . allNodesHidden ? (
303316 < span className = "no-matches" > { texts . noMatches || 'No matches found' } </ span >
304317 ) : (
0 commit comments