@@ -667,10 +667,17 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
667667 * @param event
668668 */
669669 private readonly onFileListKeyDown = (event: KeyboardEvent): void => {
670- const fileList = this.renderRoot.querySelector('.file-list');
670+ console.log(event.target);
671+ let fileList: HTMLElement;
672+ if (!event.target.classList) {
673+ fileList = this.renderRoot.querySelector('.file-list-children');
674+ } else {
675+ fileList = this.renderRoot.querySelector('.file-list');
676+ }
671677 let focusedItem: HTMLElement;
672678
673679 if (!fileList?.children.length) {
680+ console.log('no children for ', fileList);
674681 return;
675682 }
676683
@@ -926,27 +933,47 @@ export class MgtFileList extends MgtTemplatedTaskComponent implements CardSectio
926933
927934 private readonly showChildren = (file: DriveItem | SharedInsight, e?: MouseEvent) => {
928935 const itemDOM = this.renderRoot.querySelector(`#file-list-item-${file.id}`);
929- if (itemDOM) {
930- this.renderChildren(file, itemDOM);
931- }
936+ this.renderChildren(file, itemDOM);
932937 };
933938
934939 private readonly renderChildren = (file: DriveItem | SharedInsight, itemDOM: Element) => {
935- const container = document.createElement('div');
936- const itemListDOM = document.createElement('ul');
937- container.appendChild(itemListDOM);
938- const children = file?.children ?? [];
939- for (const f of children) {
940- const itemDOM = document.createElement('li');
941- // TODO: fix for disambiguation
942- const fileDOM = document.createElement('mgt-file');
943- fileDOM.setAttribute('fileDetails', JSON.stringify(f));
944- fileDOM.setAttribute('view', this.itemView);
945- itemDOM.appendChild(fileDOM);
946- itemListDOM.appendChild(itemDOM);
940+ const childrenContainer = this.renderRoot.querySelector(`#file-list-children-${file?.id}`);
941+ if (!childrenContainer) {
942+ // create and show the children container
943+ const container = document.createElement('div');
944+ container.setAttribute('id', `file-list-children-${file?.id}`);
945+ container.setAttribute('class', 'file-list-children-show');
946+
947+ const itemListDOM = document.createElement('ul');
948+ itemListDOM.setAttribute('class', 'file-list-children');
949+ container.appendChild(itemListDOM);
950+ const children = file?.children ?? [];
951+ for (const f of children) {
952+ const li = document.createElement('li');
953+ // TODO: fix for disambiguation
954+ const fileDOM = document.createElement('mgt-file');
955+ fileDOM.setAttribute('fileDetails', JSON.stringify(f));
956+ fileDOM.setAttribute('view', this.itemView);
957+ // add key down/up on the list
958+ li.addEventListener('keydown', this.onFileListKeyDown);
959+ li.setAttribute('class', 'file-item');
960+ li.appendChild(fileDOM);
961+ itemListDOM.appendChild(li);
962+ }
963+
964+ // a11y - set tabindex on first element
965+ itemListDOM.firstElementChild.setAttribute('tabindex', '0');
966+ itemListDOM.firstElementChild.setAttribute('focus', '0');
967+ this._focusedItemIndex = 0;
968+ itemDOM.after(container);
969+ } else {
970+ // toggle to show/hide the children container
971+ if (childrenContainer.classList.contains('file-list-children-hide')) {
972+ childrenContainer.setAttribute('class', 'file-list-children-show');
973+ } else {
974+ childrenContainer.setAttribute('class', 'file-list-children-hide');
975+ }
947976 }
948- // TODO: fix for display and hiding
949- itemDOM.appendChild(container);
950977 };
951978
952979 /**
0 commit comments