diff --git a/src/components/select.tsx b/src/components/select.tsx index 2dd1c2e..5c6d77e 100644 --- a/src/components/select.tsx +++ b/src/components/select.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import styled from "styled-components"; export interface IItemProps { @@ -19,51 +19,58 @@ const List = styled.select` padding: 0.5rem; `; -const update = ( - items: Array, - onChange: (item: any) => void, - e: React.ChangeEvent, -) => { - onChange(items.find((item) => item.value.toString() === e.target.value)); -}; - const Select = ({ items, onChange, current, className, testId, -}: ISelectProps) => ( - update(items, onChange, e)} - className={className} - > - {items.map(({ label, value }, index) => { - if (label === current) { - return ( - - ); - } else { - return ( - - ); - } - })} - -); +}: ISelectProps) => { + const [selected, setSelected] = useState(current); + + const update = ( + items: Array, + onChange: (item: any) => void, + event: React.ChangeEvent, + ) => { + setSelected(event.target.value); + onChange( + items.find((item) => item.value.toString() === event.target.value), + ); + }; + + return ( + update(items, onChange, e)} + className={className} + value={selected} + > + {items.map(({ label, value }, index) => { + if (label === current) { + return ( + + ); + } else { + return ( + + ); + } + })} + + ); +}; export default Select; diff --git a/src/components/settings.tsx b/src/components/settings.tsx index 72faa12..58845af 100644 --- a/src/components/settings.tsx +++ b/src/components/settings.tsx @@ -101,8 +101,8 @@ const Settings = ({ themes, search }: ISettingsProps) => { const [newLightTheme, setNewLightTheme] = useState(); const [newDarkTheme, setNewDarkTheme] = useState(); - const currentLightTheme = getTheme("light").label; - const currentDarkTheme = getTheme("dark").label; + const currentLightTheme = getTheme("light").value; + const currentDarkTheme = getTheme("dark").value; if (themes || search) { return (