mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-11-14 17:35:35 +01:00
Add custom order ability of Select options
This commit is contained in:
parent
0beb1f0418
commit
a7d7e59028
|
@ -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.
|
* This is free software, licensed under the GNU General Public License v3.
|
||||||
* See /LICENSE for more information.
|
* See /LICENSE for more information.
|
||||||
|
@ -18,18 +18,23 @@ Select.propTypes = {
|
||||||
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
||||||
/** Help text message. */
|
/** Help text message. */
|
||||||
helpText: PropTypes.string,
|
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 uid = useUID();
|
||||||
|
|
||||||
const options = Object.keys(choices)
|
const keys = Object.keys(choices);
|
||||||
.sort((a, b) => a - b || a.toString().localeCompare(b.toString()))
|
if (!customOrder) {
|
||||||
.map((key) => (
|
keys.sort((a, b) => a - b || a.toString().localeCompare(b.toString()));
|
||||||
<option key={key} value={key}>
|
}
|
||||||
{choices[key]}
|
const options = keys.map((key) => (
|
||||||
</option>
|
<option key={key} value={key}>
|
||||||
));
|
{choices[key]}
|
||||||
|
</option>
|
||||||
|
));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="form-group">
|
<div className="form-group">
|
||||||
<label htmlFor={uid}>{label}</label>
|
<label htmlFor={uid}>{label}</label>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user