Skip to content

Commit 5f5bf36

Browse files
authored
Merge pull request #250 from brionmario/fix-asgardeo-v2-signup
feat: add `Select` support for `DROPDOWN` types
2 parents 4282e35 + 3a5f116 commit 5f5bf36

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.changeset/all-plants-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@asgardeo/react': patch
3+
---
4+
5+
Add `Select` support for `DROPDOWN` types
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
3+
*
4+
* WSO2 LLC. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import {FieldType} from '@asgardeo/browser';
20+
import {FC} from 'react';
21+
import {BaseSignUpOptionProps} from '../presentation/SignUp/SignUpOptionFactory';
22+
import {createField} from '../factories/FieldFactory';
23+
import {SelectOption} from '../primitives/Select/Select';
24+
25+
/**
26+
* Select input component for sign-up forms.
27+
*/
28+
const SelectInput: FC<BaseSignUpOptionProps> = ({
29+
component,
30+
formValues,
31+
touchedFields,
32+
formErrors,
33+
onInputChange,
34+
inputClassName,
35+
}) => {
36+
const config: Record<string, unknown> = component.config || {};
37+
const fieldName: string = (config['identifier'] as string) || (config['name'] as string) || component.id;
38+
const value: string = formValues[fieldName] || '';
39+
const error: string = touchedFields[fieldName] ? formErrors[fieldName] : undefined;
40+
41+
// Get options from config and convert to SelectOption format
42+
const rawOptions: string[] = (config['options'] as string[]) || [];
43+
const options: SelectOption[] = rawOptions.map((option: string) => ({
44+
label: option,
45+
value: option,
46+
}));
47+
48+
return createField({
49+
type: FieldType.Select,
50+
name: fieldName,
51+
label: (config['label'] as string) || '',
52+
placeholder: (config['placeholder'] as string) || '',
53+
required: (config['required'] as boolean) || false,
54+
value,
55+
error,
56+
options,
57+
onChange: (newValue: string): void => onInputChange(fieldName, newValue),
58+
className: inputClassName,
59+
});
60+
};
61+
62+
export default SelectInput;

packages/react/src/components/presentation/SignUp/SignUpOptionFactory.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import PasswordInput from '../../adapters/PasswordInput';
2929
import ButtonComponent from '../../adapters/SubmitButton';
3030
import TelephoneInput from '../../adapters/TelephoneInput';
3131
import TextInput from '../../adapters/TextInput';
32+
import SelectInput from '../../adapters/SelectInput';
3233
import Typography from '../../adapters/Typography';
3334
import GoogleButton from '../../adapters/GoogleButton';
3435
import GitHubButton from '../../adapters/GitHubButton';
@@ -201,6 +202,9 @@ export const createSignUpComponent = ({component, onSubmit, ...rest}: BaseSignUp
201202
case EmbeddedFlowComponentType.Form:
202203
return <FormContainer component={component} onSubmit={onSubmit} {...rest} />;
203204

205+
case EmbeddedFlowComponentType.Select:
206+
return <SelectInput component={component} onSubmit={onSubmit} {...rest} />;
207+
204208
case EmbeddedFlowComponentType.Divider:
205209
return <DividerComponent component={component} onSubmit={onSubmit} {...rest} />;
206210

packages/react/src/components/presentation/SignUp/transformer.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const convertSimpleInputToComponent = (
9696
name: string;
9797
type: string;
9898
required: boolean;
99+
options?: string[];
99100
},
100101
t: UseTranslation['t'],
101102
): EmbeddedFlowComponent => {
@@ -108,6 +109,28 @@ const convertSimpleInputToComponent = (
108109
fieldType = 'password';
109110
}
110111

112+
// Handle dropdown type
113+
if (input.type.toLowerCase() === 'dropdown') {
114+
const label: string = getInputLabel(input.name, fieldType, t);
115+
const placeholder: string = getInputPlaceholder(input.name, fieldType, t);
116+
117+
return {
118+
id: generateId('select'),
119+
type: EmbeddedFlowComponentType.Select,
120+
variant: 'SELECT',
121+
config: {
122+
type: fieldType,
123+
label,
124+
placeholder,
125+
required: input.required as boolean,
126+
identifier: input.name,
127+
hint: '',
128+
options: input.options || [],
129+
},
130+
components: [],
131+
};
132+
}
133+
111134
const variant: 'TEXT' | 'EMAIL' | 'PASSWORD' = getInputVariant(fieldType, input.name);
112135
const label: string = getInputLabel(input.name, fieldType, t);
113136
const placeholder: string = getInputPlaceholder(input.name, fieldType, t);

0 commit comments

Comments
 (0)