@@ -55,46 +55,57 @@ const AttributeButtonPopover = <T extends ReactText>({
55
55
filterable = false ,
56
56
isOpen,
57
57
} : AttributeButtonPopoverProps < T > ) => {
58
- const AttributeSelect = Select . ofType < T > ( ) ;
59
58
const itemPredicate = ( query : string , item : T ) => {
60
59
return String ( item ) . toLowerCase ( ) . includes ( query . toLowerCase ( ) ) ;
61
60
} ;
62
61
const [ sliderValue , setSliderValue ] = useState ( 0 ) ;
63
62
useEffect ( ( ) => {
64
63
setSliderValue ( Number ( currentValue ) ) ;
65
64
} , [ isOpen , currentValue ] ) ;
65
+
66
+ const formatDisplayText = ( text : string ) : string => {
67
+ // TODO: for doantrang982/eng-77-decouple-display-from-output: Create formatDisplayText from configPage
68
+ // const match = text.match(/\[\[(.*?)\]\]/);
69
+ // if (match && match[1]) {
70
+ // return match[1];
71
+ // }
72
+ return text ;
73
+ } ;
74
+
75
+ // Only show filter if we have more than 10 items
76
+ const shouldFilter = filterable && items . length > 10 ;
77
+
66
78
return (
67
- < AttributeSelect
79
+ < MenuItemSelect
68
80
className = "inline-menu-item-select"
69
- itemRenderer = { ( item , { modifiers, handleClick } ) => (
70
- < MenuItem
71
- key = { item }
72
- text = { item }
73
- active = { modifiers . active }
74
- onClick = { handleClick }
75
- />
76
- ) }
77
81
itemPredicate = { itemPredicate }
78
82
items = { items }
83
+ activeItem = { currentValue as T }
84
+ filterable = { shouldFilter }
85
+ // transformItem={(item) => formatDisplayText(String(item))}
79
86
onItemSelect = { ( s ) => {
80
87
updateBlock ( {
81
88
text : `${ attributeName } :: ${ s } ` ,
82
89
uid,
83
90
} ) ;
91
+ setIsOpen ( false ) ;
92
+ } }
93
+ popoverProps = { {
94
+ isOpen,
95
+ onClose : ( ) => setIsOpen ( false ) ,
84
96
} }
85
- activeItem = { currentValue as T }
86
- // onActiveItemChange={} // TODO: get this working for keyboard support
87
- filterable = { filterable }
88
97
>
89
- < Button
90
- className = "roamjs-attribute-select-button p-0 ml-1"
91
- icon = "chevron-down"
92
- style = { { minHeight : 15 , minWidth : 20 } }
93
- intent = "primary"
94
- minimal
95
- onClick = { ( ) => setIsOpen ( true ) }
96
- />
97
- </ AttributeSelect >
98
+ { ( ) => (
99
+ < Button
100
+ className = "roamjs-attribute-select-button p-0 ml-1"
101
+ icon = "chevron-down"
102
+ style = { { minHeight : 15 , minWidth : 20 } }
103
+ intent = "primary"
104
+ minimal
105
+ onClick = { ( ) => setIsOpen ( true ) }
106
+ />
107
+ ) }
108
+ </ MenuItemSelect >
98
109
) ;
99
110
} ;
100
111
@@ -214,6 +225,7 @@ const AttributeButton = ({
214
225
uid = { uid }
215
226
currentValue = { currentValue }
216
227
isOpen = { isOpen }
228
+ filterable = { true }
217
229
/>
218
230
) }
219
231
</ >
0 commit comments