From a7d7e5902805ea5718cd72f383c149f1142b73f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Sa=C5=A1ek?= Date: Mon, 11 Oct 2021 14:22:25 +0200 Subject: [PATCH] Add custom order ability of Select options --- src/bootstrap/Select.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/Select.js b/src/bootstrap/Select.js index c60e282..5fdbdc1 100644 --- a/src/bootstrap/Select.js +++ b/src/bootstrap/Select.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/) + * Copyright (C) 2019-2021 CZ.NIC z.s.p.o. (http://www.nic.cz/) * * This is free software, licensed under the GNU General Public License v3. * See /LICENSE for more information. @@ -18,18 +18,23 @@ Select.propTypes = { value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, /** Help text message. */ helpText: PropTypes.string, + /** Turns on/off alphabetical ordering of the Select options. */ + customOrder: PropTypes.bool, }; -export function Select({ label, choices, helpText, ...props }) { +export function Select({ label, choices, helpText, customOrder, ...props }) { const uid = useUID(); - const options = Object.keys(choices) - .sort((a, b) => a - b || a.toString().localeCompare(b.toString())) - .map((key) => ( - - )); + const keys = Object.keys(choices); + if (!customOrder) { + keys.sort((a, b) => a - b || a.toString().localeCompare(b.toString())); + } + const options = keys.map((key) => ( + + )); + return (