fix: correctly display versions list in Select component

fix: was unable to create new worlds by pressing Enter
This commit is contained in:
Vitaly Turovsky 2024-08-24 04:34:35 +03:00
commit 42e53c8efc
4 changed files with 9 additions and 9 deletions

View file

@ -81,7 +81,7 @@ export default ({ cancelClick, createClick, customizeClick, versions, defaultVer
</Button>
<Button disabled={!title} onClick={createClick}>Create</Button>
</div>
<div className='muted' style={{ fontSize: 9 }}>Note: store important saves in folders on the drive!</div>
<div className='muted' style={{ fontSize: 9 }}>Note: save important worlds in folders on your hard drive!</div>
<div className='muted' style={{ fontSize: 9 }}>{quota}</div>
</Screen>
}

View file

@ -14,7 +14,7 @@ export const Primary: Story = {
args: {
initialOptions: [{ value: '1', label: 'option 1' }, { value: '2', label: 'option 2' }, { value: '3', label: 'option 3' },],
updateOptions (options) {},
processInput (input) {
getCssOnInput (input) {
console.log('input:', input)
if (input === 'option 3') return { border: '1px solid yellow' } as CSSProperties
},

View file

@ -13,7 +13,7 @@ export interface OptionStorage {
interface Props {
initialOptions: OptionStorage[]
updateOptions: (options: string) => void
processInput?: (input: string) => CSSProperties | undefined
getCssOnInput?: (input: string) => CSSProperties | undefined
processOption?: (option: string) => string
onValueChange?: (newVal: string) => void
defaultValue?: { value: string, label: string }
@ -27,7 +27,7 @@ interface Props {
export default ({
initialOptions,
updateOptions,
processInput,
getCssOnInput,
onValueChange,
defaultValue,
containerStyle,
@ -40,7 +40,6 @@ export default ({
return <Creatable
options={initialOptions}
aria-invalid="true"
defaultValue={defaultValue}
blurInputOnSelect={true}
hideSelectedOptions={false}
@ -56,7 +55,7 @@ export default ({
setInputValue(e?.label)
onValueChange?.(e?.value ?? '')
updateOptions?.(e?.value ?? '')
setInputStyle(processInput?.(e?.value ?? '') ?? {})
setInputStyle(getCssOnInput?.(e?.value ?? '') ?? {})
}}
onInputChange={(e) => {
setIsFirstClick(false)
@ -72,6 +71,7 @@ export default ({
onMenuOpen={() => {
setIsFirstClick(true)
}}
menuPortalTarget={document.body}
classNames={{
control (state) {
return styles.container
@ -84,7 +84,8 @@ export default ({
}
}}
styles={{
container (base, state) { return { ...base, position: 'relative' } },
menuPortal (base, state) { return { ...base, zIndex: 10, transform: 'scale(var(--guiScale))', transformOrigin: 'top left' } },
container (base, state) { return { ...base, position: 'relative', zIndex: 10 } },
control (base, state) { return { ...containerStyle, ...inputStyle } },
menu (base, state) { return { position: 'absolute', zIndex: 10 } },
option (base, state) {
@ -106,4 +107,3 @@ export default ({
}}
/>
}

View file

@ -23,7 +23,7 @@ export default (
}}
onValueChange={onChange}
containerStyle={containerStyle ?? { width: '190px' }}
processInput={(value) => {
getCssOnInput={(value) => {
if (!versions || !value) return {}
const parsedsupportedVersions = versions.map(x => x.value.split('.').map(Number))
const parsedValue = value.split('.').map(Number)