@@ -80,134 +80,75 @@ export const disableSuggestions = () => html`
8080` ;
8181
8282export const dynamicGroupId = ( ) => html `
83- < mgt-people-picker id ="picker "> </ mgt-people-picker >
84- < div >
85- < p class ="notes "> Pick a group:</ p >
86- < div class ="groups ">
87- < button aria-label ="Select a group " id ="showHideGroups "> Select a group</ button >
88- < ul id ="groupChooser "> </ ul >
89- </ div >
90- < p class ="notes "> People chosen:</ p >
91- < div id ="chosenPeople "> </ div >
92- </ div >
93-
94- < style >
95- body {
96- font-family : 'Segoe UI' , 'Segoe UI Web (West European)' , 'Segoe UI' , -apple-system, BlinkMacSystemFont, Roboto,
97- 'Helvetica Neue' , sans-serif;
98- }
99-
100- .notes {
101- font-size : 12px ;
102- margin-bottom : 2px ;
103- }
104- .groups {
105- max-width : 200px ;
106- }
83+ < div class ="groups ">
84+ < label class ="notes "> Pick a group:
85+ < select id ="groupChooser ">
86+ < option > </ option >
87+ </ select >
88+ </ label >
89+ </ div >
90+ < mgt-people-picker id ="picker "> </ mgt-people-picker >
10791
108- # showHideGroups {
109- background-color : # 287ab1 ;
110- color : white;
111- padding : 8px ;
112- font-size : 16px ;
113- border : none;
114- cursor : pointer;
115- width : 100% ;
116- }
11792
118- # showHideGroups : hover , # showHideGroups : focus {
119- background-color : # 4488EC ;
120- }
93+ < style >
94+ .notes {
95+ font-size : 12px ;
96+ }
97+
98+ .groups {
99+ max-width : 200px ;
100+ margin-bottom : 16px ;
101+ }
102+
103+ # groupChooser {
104+ position : inherit;
105+ width : 100% ;
106+ max-height : 300px ;
107+ overflow : scroll;
108+ padding-left : 3px ;
109+ }
110+ </ style >
111+ < script type ="module ">
112+ import { Providers , ProviderState } from '@microsoft/mgt-element' ;
113+
114+ let picker = document . getElementById ( 'picker' ) ;
115+ let groupChooser = document . getElementById ( 'groupChooser' ) ;
116+
117+
118+ loadGroups ( ) ;
119+ Providers . onProviderUpdated ( loadGroups ) ;
120+
121+ function loadGroups ( ) {
122+ let provider = Providers . globalProvider ;
123+ if ( provider && provider . state === ProviderState . SignedIn ) {
124+ let client = provider . graph . client ;
125+
126+ client
127+ . api ( '/groups' )
128+ . get ( )
129+ . then ( groups => {
130+ for ( let group of groups . value ) {
131+ const id = group . id ;
132+ let option = document . createElement ( 'option' ) ;
133+ option . setAttribute ( "value" , id ) ;
134+ option . innerText = group . displayName ;
135+ groupChooser . appendChild ( option ) ;
136+ }
137+ } ) ;
138+ }
139+ }
121140
122- # groupChooser {
123- display : none;
124- position : inherit;
125- background-color : # f1f1f1 ;
126- width : 100% ;
127- box-shadow : 0px 8px 8px 0px rgba (0 , 0 , 0 , 0.2 );
128- max-height : 300px ;
129- overflow : scroll;
130- padding-left : 3px ;
131- }
132- ul {
133- margin : 0px ;
134- display : inherit;
135- }
136- ul > li {
137- color : black;
138- text-decoration : none;
139- display : block;
140- border-bottom : 1px solid;
141- font-size : 12px ;
142- cursor : pointer;
143- }
144- ul > li : hover , ul > li : focus {
145- background-color : lightgray;
146- }
147- </ style >
148- < script type ="module ">
149- import { Providers , ProviderState } from '@microsoft/mgt-element' ;
150-
151- let picker = document . getElementById ( 'picker' ) ;
152- let chosenArea = document . getElementById ( 'chosenPeople' ) ;
153- let groupChooser = document . getElementById ( 'groupChooser' ) ;
154- let button = document . getElementById ( 'showHideGroups' ) ;
155- button . addEventListener ( "click" , showHideGroups ) ;
156-
157- loadGroups ( ) ;
158- Providers . onProviderUpdated ( loadGroups ) ;
159-
160- function showHideGroups ( ) {
161- const display = groupChooser . style . display ;
162- if ( display === "none" || display === "" ) {
163- groupChooser . style . display = "inline-block" ;
164- } else {
165- groupChooser . style . display = "none" ;
166- }
167- }
168- function loadGroups ( ) {
169- let provider = Providers . globalProvider ;
170- if ( provider && provider . state === ProviderState . SignedIn ) {
171- let client = provider . graph . client ;
172-
173- client
174- . api ( '/groups' )
175- . get ( )
176- . then ( groups => {
177- for ( let group of groups . value ) {
178- const id = group . id ;
179- let option = document . createElement ( 'li' ) ;
180- option . setAttribute ( "value" , id ) ;
181- option . innerText = group . displayName ;
182- option . onclick = function ( event ) {
183- const id = event . target . getAttribute ( "value" ) ;
184- const displayName = event . target . innerText . trim ( ) ;
185- button . innerText = displayName ;
186- setGroupValue ( id ) ;
187- showHideGroups ( ) ;
188- }
189-
190- groupChooser . appendChild ( option ) ;
191- }
192- } ) ;
193- }
194- }
141+ function setGroupValue ( selected ) {
142+ picker . setAttribute ( 'group-id' , selected ) ;
143+ }
195144
196- picker . addEventListener ( 'selectionChanged' , function ( e ) {
197- //reset area
198- chosenArea . innerHTML = '' ;
199- //render selected people to chosen people div
200- for ( var i = 0 ; i < e . detail . length ; i ++ ) {
201- let newElem = document . createElement ( 'div' ) ;
202- newElem . innerHTML = e . detail [ i ] . displayName + ' ' + e . detail [ i ] . id ;
203- chosenArea . append ( newElem ) ;
204- }
205- } ) ;
206-
207- function setGroupValue ( selected ) {
208- picker . setAttribute ( 'group-id' , selected ) ;
209- }
210- </ script >
145+ groupChooser . addEventListener ( 'change' , function ( e ) {
146+ const selection = e . target . value ;
147+ if ( selection !== - 1 ) {
148+ setGroupValue ( selection ) ;
149+ }
150+ } ) ;
151+ </ script >
211152` ;
212153
213154export const pickPeopleAndGroups = ( ) => html `
0 commit comments