diff --git a/src/KeyboardLayouts/index.ts b/src/KeyboardLayouts/index.ts index fdcc7fd..5a3dd18 100644 --- a/src/KeyboardLayouts/index.ts +++ b/src/KeyboardLayouts/index.ts @@ -4,8 +4,17 @@ export const keyboards: { [k: string]: QmkInfoJson } = {}; // Insert the global values from a cache to keyboards list if (typeof window !== "undefined" && (window as any)["INFO_JSON_FILES"]) { - Object.keys((window as any)["INFO_JSON_FILES"]).forEach(key => { - let value = (window as any)["INFO_JSON_FILES"][key]; - keyboards[key] = value; - }); + let files = (window as any)["INFO_JSON_FILES"]; + + // Sort the keyboards alphabetically by their displayed name (Issue #15) + // so the keyboard dropdown appears in a predictable, sorted order. + Object.keys(files) + .sort((a, b) => { + let nameA = (files[a].keyboard_name || a).toLowerCase(); + let nameB = (files[b].keyboard_name || b).toLowerCase(); + return nameA > nameB ? 1 : nameB > nameA ? -1 : 0; + }) + .forEach(key => { + keyboards[key] = files[key]; + }); }