Skip to content

Commit 622f000

Browse files
musalegavinbarron
andauthored
fix: enable keyboard navigation in the picker (#2324)
Signed-off-by: Martin Musale <[email protected]> Co-authored-by: Gavin Barron <[email protected]>
1 parent d084665 commit 622f000

19 files changed

+38
-15
lines changed

packages/mgt-components/src/components/mgt-picker/mgt-picker.ts

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,28 @@ export class MgtPicker extends MgtTemplatedComponent {
226226
*/
227227
protected renderPicker(): TemplateResult {
228228
return mgtHtml`
229-
<fluent-combobox current-value=${ifDefined(
230-
this.selectedValue
231-
)} part="picker" class="picker" id="combobox" autocomplete="list" placeholder=${this.placeholder}>
229+
<fluent-combobox
230+
@keydown=${this.handleComboboxKeydown}
231+
current-value=${ifDefined(this.selectedValue)}
232+
part="picker"
233+
class="picker"
234+
id="combobox"
235+
autocomplete="list"
236+
placeholder=${this.placeholder}>
232237
${this.response.map(
233238
item => html`
234-
<fluent-option value=${item.id} @click=${(e: MouseEvent) => this.handleClick(e, item)}> ${
235-
item[this.keyName]
236-
} </fluent-option>`
239+
<fluent-option
240+
value=${item.id}
241+
@click=${(e: MouseEvent) => this.handleClick(e, item)}>
242+
${item[this.keyName]}
243+
</fluent-option>`
237244
)}
238245
</fluent-combobox>
239246
`;
240247
}
241248

242249
/**
243-
* Render picker.
250+
* Renders mgt-get which does a GET request to the resource.
244251
*
245252
* @protected
246253
* @returns {TemplateResult}
@@ -285,4 +292,28 @@ export class MgtPicker extends MgtTemplatedComponent {
285292
private handleClick(e: MouseEvent, item: any) {
286293
this.fireCustomEvent('selectionChanged', item, true, false, true);
287294
}
295+
296+
/**
297+
* Handles getting the fluent option item in the dropdown and fires a custom
298+
* event with it when you press Enter or Backspace keys.
299+
*
300+
* @param {KeyboardEvent} e
301+
*/
302+
private handleComboboxKeydown = (e: KeyboardEvent) => {
303+
let value: string;
304+
let item: any;
305+
const keyName: string = e.key;
306+
const comboBox: HTMLElement = e.target as HTMLElement;
307+
const fluentOptionEl = comboBox.querySelector('.selected');
308+
if (fluentOptionEl) {
309+
value = fluentOptionEl.getAttribute('value');
310+
}
311+
312+
if (['Enter'].includes(keyName)) {
313+
if (value) {
314+
item = this.response.filter(res => res.id === value).pop();
315+
this.fireCustomEvent('selectionChanged', item, true, false, true);
316+
}
317+
}
318+
};
288319
}

packages/mgt-components/src/components/mgt-tasks-base/mgt-tasks-base.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,6 @@ export abstract class MgtTasksBase extends MgtTemplatedComponent {
181181
*/
182182
protected abstract renderPicker(): TemplateResult;
183183

184-
/**
185-
* Render the generic picker.
186-
*
187-
* @protected
188-
* @memberof MgtTasksBase
189-
*/
190-
protected abstract renderPicker(): TemplateResult;
191-
192184
/**
193185
* Render the list of todo tasks
194186
*

samples/sp-mgt/.eslintrc.js

100755100644
File mode changed.

samples/sp-mgt/.gitignore

100755100644
File mode changed.

samples/sp-mgt/.npmignore

100755100644
File mode changed.

samples/sp-mgt/README.md

100755100644
File mode changed.

samples/sp-mgt/config/deploy-azure-storage.json

100755100644
File mode changed.

samples/sp-mgt/config/write-manifests.json

100755100644
File mode changed.

samples/sp-mgt/gulpfile.js

100755100644
File mode changed.

samples/sp-mgt/src/index.ts

100755100644
File mode changed.

0 commit comments

Comments
 (0)