Javascript to simulate a file chooser gui

I want to be able to simulate a file chooser in Javascript to allow the user to choose a file on the server. Obviously, the server will control which files can be selected. In fact, assume the server returns a list of files such as

root/dir1/file1.txt
root/dir1/file2.txt
root/dir1/file3.txt
root/dir2/file4.txt
root/dir2/file5.txt

I could use a simple drop-down list to allow the user to choose, but since there might be a lot of files, I want them to be able to navigate the directories.

In this case, I would want to see something like

enter image description here

enter image description here

the result of the select would just be a fully qualified directory name that the client can then use in subsequent calls