@@ -61,7 +61,7 @@ Default.args = {
6161
6262/**
6363 * Display always the dropdown after the element was clicked on.
64- * Do not wait until the query input was startet .
64+ * Do not wait until the query input was started .
6565 */
6666export const dropdownOnFocus = Template . bind ( { } ) ;
6767dropdownOnFocus . args = {
@@ -259,3 +259,43 @@ CustomSearch.args = {
259259 return item . testId . toLowerCase ( ) . includes ( query ) || item . testLabel . toLowerCase ( ) . includes ( query ) ;
260260 } ,
261261} ;
262+
263+ const SelectionNotificationComponent = ( ) : React . JSX . Element => {
264+ const [ notification , setNotification ] = useState < string | null > ( null ) ;
265+
266+ const availableItems = useMemo < string [ ] > ( ( ) => [ "existing item" ] , [ ] ) ;
267+
268+ const identity = useCallback ( ( item : string ) : string => item , [ ] ) ;
269+
270+ const handleOnSelect = useCallback ( ( params : MultiSuggestFieldSelectionProps < string > ) => {
271+ if ( params . newlySelected ) {
272+ setNotification ( `Element added: ${ params . newlySelected } ` ) ;
273+ } else if ( params . newlyRemoved ) {
274+ setNotification ( `Element removed: ${ params . newlyRemoved } ` ) ;
275+ }
276+
277+ setTimeout ( ( ) => setNotification ( null ) , 3000 ) ;
278+ } , [ ] ) ;
279+
280+ return (
281+ < OverlaysProvider >
282+ < MultiSuggestField < string >
283+ items = { availableItems }
284+ prePopulateWithItems = { true }
285+ onSelection = { handleOnSelect }
286+ itemId = { identity }
287+ itemLabel = { identity }
288+ createNewItemFromQuery = { identity }
289+ />
290+ { notification && (
291+ < Notification > { notification } </ Notification >
292+ ) }
293+ </ OverlaysProvider >
294+ ) ;
295+ } ;
296+
297+ /**
298+ * Demonstrates the `newlySelected` and `newlyRemoved` properties of the `onSelection` callback.
299+ * A notification appears when an element is added or removed from the selection.
300+ */
301+ export const selectionNotification = SelectionNotificationComponent . bind ( { } ) ;
0 commit comments