11import uuid from '@dojo/core/uuid' ;
22import { v , w } from '@dojo/widget-core/d' ;
3- import { DNode , WNode } from '@dojo/widget-core/interfaces' ;
3+ import { Constructor , DNode , WNode } from '@dojo/widget-core/interfaces' ;
44import { ThemeableMixin , ThemeableProperties , theme } from '@dojo/widget-core/mixins/Themeable' ;
5- import { WidgetBase , diffProperty } from '@dojo/widget-core/WidgetBase' ;
5+ import { WidgetBase } from '@dojo/widget-core/WidgetBase' ;
6+ import { diffProperty } from '@dojo/widget-core/decorators/diffProperty' ;
67import { reference } from '@dojo/widget-core/diff' ;
7- import WidgetRegistry from '@dojo/widget-core/WidgetRegistry' ;
88import ResultItem from './ResultItem' ;
99import ResultMenu from './ResultMenu' ;
1010import { Keys } from '../common/util' ;
@@ -21,8 +21,8 @@ import * as iconCss from '../common/styles/icons.m.css';
2121 *
2222 * @property autoBlur Determines whether the input should blur after value selection
2323 * @property clearable Determines whether the input should be able to be cleared
24- * @property customResultItem Can be used to render a custom result
25- * @property customResultMenu Can be used to render a custom result menu
24+ * @property CustomResultItem Can be used to render a custom result
25+ * @property CustomResultMenu Can be used to render a custom result menu
2626 * @property disabled Prevents user interaction and styles content accordingly
2727 * @property getResultLabel Can be used to get the text label of a result based on the underlying result object
2828 * @property inputProperties TextInput properties to set on the underlying input
@@ -43,8 +43,8 @@ import * as iconCss from '../common/styles/icons.m.css';
4343export interface ComboBoxProperties extends ThemeableProperties {
4444 autoBlur ?: boolean ;
4545 clearable ?: boolean ;
46- customResultItem ?: any ;
47- customResultMenu ?: any ;
46+ CustomResultItem ?: Constructor < ResultItem > ;
47+ CustomResultMenu ?: Constructor < ResultMenu > ;
4848 disabled ?: boolean ;
4949 getResultLabel ?( result : any ) : string ;
5050 inputProperties ?: TextInputProperties ;
@@ -73,6 +73,7 @@ export const ComboBoxBase = ThemeableMixin(WidgetBase);
7373
7474@theme ( css )
7575@theme ( iconCss )
76+ @diffProperty ( 'results' , reference )
7677export default class ComboBox extends ComboBoxBase < ComboBoxProperties > {
7778 private _activeIndex : number | undefined ;
7879 private _focused : boolean ;
@@ -82,29 +83,12 @@ export default class ComboBox extends ComboBoxBase<ComboBoxProperties> {
8283 private _menuId = uuid ( ) ;
8384 private _open : boolean ;
8485 private _wasOpen : boolean ;
85- private _registry : WidgetRegistry ;
86-
87- constructor ( ) {
88- /* istanbul ignore next: disregard transpiled `super`'s "else" block */
89- super ( ) ;
90-
91- this . _registry = this . _createRegistry ( ResultItem , ResultMenu ) ;
92- this . getRegistries ( ) . add ( this . _registry ) ;
93- }
9486
9587 private _closeMenu ( ) {
9688 this . _open = false ;
9789 this . invalidate ( ) ;
9890 }
9991
100- private _createRegistry ( customResultItem : any , customResultMenu : any ) {
101- const registry = new WidgetRegistry ( ) ;
102- registry . define ( 'result-item' , customResultItem ) ;
103- registry . define ( 'result-menu' , customResultMenu ) ;
104-
105- return registry ;
106- }
107-
10892 private _getResultLabel ( result : any ) {
10993 const { getResultLabel } = this . properties ;
11094
@@ -307,35 +291,21 @@ export default class ComboBox extends ComboBoxBase<ComboBoxProperties> {
307291 }
308292 }
309293
310- @diffProperty ( 'customResultItem' , reference )
311- @diffProperty ( 'customResultMenu' , reference )
312- @diffProperty ( 'results' , reference )
313- protected onPropertiesChanged ( previousProperties : any , newProperties : any ) {
314- const {
315- customResultItem = ResultItem ,
316- customResultMenu = ResultMenu
317- } = newProperties ;
318-
319- const registry = this . _createRegistry ( customResultItem , customResultMenu ) ;
320- this . getRegistries ( ) . replace ( this . _registry , registry ) ;
321- this . _registry = registry ;
322- }
323-
324294 protected renderMenu ( results : any [ ] ) : WNode | null {
325- const { theme = { } , isResultDisabled } = this . properties ;
295+ const { theme = { } , isResultDisabled, CustomResultMenu = ResultMenu , CustomResultItem } = this . properties ;
326296
327297 if ( results . length === 0 || ! this . _open ) {
328298 return null ;
329299 }
330300
331- return w < ResultMenu > ( 'result-menu' , {
301+ return w ( CustomResultMenu , {
332302 getResultLabel : this . _getResultLabel ,
303+ CustomResultItem,
333304 id : this . _menuId ,
334305 isResultDisabled,
335306 onResultMouseDown : this . _onResultMouseDown ,
336307 onResultMouseEnter : this . _onResultMouseEnter ,
337308 onResultMouseUp : this . _onResultMouseUp ,
338- registry : this . _registry ,
339309 results,
340310 selectedIndex : this . _activeIndex ,
341311 theme
0 commit comments