@@ -63,26 +63,15 @@ export interface Props extends StandardFunctionProps {
6363
6464type State = {
6565 showTypeAheadMenu : boolean
66- selectedItem ?: TypeAheadMenuItem
6766}
6867
6968export class GlobalHeaderDropdown extends React . Component < Props , State > {
7069 constructor ( props : Props ) {
7170 super ( props )
7271 this . state = {
7372 showTypeAheadMenu : this . props . onlyRenderSubmenu ?? false ,
74- selectedItem : this . props . typeAheadSelectedOption || null ,
7573 }
7674 }
77-
78- componentDidUpdate ( ) {
79- if ( this . props . typeAheadSelectedOption !== this . state . selectedItem ) {
80- this . setState ( {
81- selectedItem : this . props . typeAheadSelectedOption ,
82- } )
83- }
84- }
85-
8675 private dropdownButton = (
8776 active : boolean ,
8877 onClick : ( e : MouseEvent < HTMLElement > ) => void
@@ -92,8 +81,8 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
9281 defaultTestID,
9382 dropdownButtonIcon,
9483 dropdownButtonSize,
84+ typeAheadSelectedOption,
9585 } = this . props
96- const { selectedItem} = this . state
9786 return (
9887 < Dropdown . Button
9988 active = { active }
@@ -103,7 +92,7 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
10392 testID = { defaultTestID }
10493 trailingIcon = { dropdownButtonIcon || IconFont . DoubleCaretVertical }
10594 >
106- { selectedItem ?. name || defaultButtonText }
95+ { typeAheadSelectedOption ?. name || defaultButtonText }
10796 </ Dropdown . Button >
10897 )
10998 }
@@ -154,17 +143,17 @@ export class GlobalHeaderDropdown extends React.Component<Props, State> {
154143 }
155144
156145 private renderTypeAheadMenu = ( ) => {
157- const { typeAheadMenuOptions} = this . props
158- const { selectedItem} = this . state
159146 const {
160147 dropdownMenuStyle,
148+ typeAheadMenuOptions,
149+ typeAheadSelectedOption,
161150 typeAheadEventPrefix,
162151 typeAheadInputPlaceholder,
163152 typeAheadOnSelectOption,
164153 } = this . props
165154 return (
166155 < GlobalHeaderTypeAheadMenu
167- defaultSelectedItem = { selectedItem }
156+ defaultSelectedItem = { typeAheadSelectedOption ?? null }
168157 onSelectOption = { typeAheadOnSelectOption }
169158 style = { dropdownMenuStyle }
170159 testID = { this . props . typeAheadTestID }
0 commit comments