Skip to content

Commit

Permalink
Fix: required attribute not passed to select element (#2944)
Browse files Browse the repository at this point in the history
* fix: required atribute not passed to select element

* changeset
  • Loading branch information
m1aw authored Dec 9, 2024
1 parent ba132fc commit 7833841
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-lizards-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': patch
---

Fix bug where Country field and State field where not showing the correct required attribute.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const formatCountries = (countries: Array<CountryFieldItem>, allowedCountries: s
};

export default function CountryField(props: CountryFieldProps) {
const { allowedCountries = [], classNameModifiers = [], errorMessage, onDropdownChange, value } = props;
const { allowedCountries = [], classNameModifiers = [], errorMessage, onDropdownChange, value, required } = props;
const { i18n, loadingContext } = useCoreContext();
const [countries, setCountries] = useState<CountryFieldItem[]>([]);
const [loaded, setLoaded] = useState<boolean>(false);
Expand Down Expand Up @@ -53,7 +53,14 @@ export default function CountryField(props: CountryFieldProps) {
i18n={i18n}
readOnly={readOnly && !!value}
>
<Select onChange={onDropdownChange} name={'country'} selectedValue={value} items={countries} readonly={readOnly && !!value} />
<Select
onChange={onDropdownChange}
name={'country'}
selectedValue={value}
items={countries}
readonly={readOnly && !!value}
required={required}
/>
</Field>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function FieldContainer(props: FieldContainerProps) {
errorMessage={errorMessage}
onDropdownChange={props.onDropdownChange}
value={value}
required={!isOptional}
/>
);
case 'stateOrProvince':
Expand All @@ -57,6 +58,7 @@ function FieldContainer(props: FieldContainerProps) {
selectedCountry={selectedCountry}
specifications={props.specifications}
value={value}
required={!isOptional}
/>
);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { StateFieldItem, StateFieldProps } from '../types';
import Select from '../../FormFields/Select';

export default function StateField(props: StateFieldProps) {
const { classNameModifiers, label, onDropdownChange, readOnly, selectedCountry, specifications, value } = props;
const { classNameModifiers, label, onDropdownChange, readOnly, selectedCountry, specifications, value, required } = props;
const { i18n, loadingContext } = useCoreContext();
const [states, setStates] = useState<StateFieldItem[]>([]);
const [loaded, setLoaded] = useState<boolean>(false);
Expand Down Expand Up @@ -44,7 +44,14 @@ export default function StateField(props: StateFieldProps) {
i18n={i18n}
readOnly={readOnly && !!value}
>
<Select name={'stateOrProvince'} onChange={onDropdownChange} selectedValue={value} items={states} readonly={readOnly && !!value} />
<Select
name={'stateOrProvince'}
onChange={onDropdownChange}
selectedValue={value}
items={states}
required={required}
readonly={readOnly && !!value}
/>
</Field>
);
}
2 changes: 2 additions & 0 deletions packages/lib/src/components/internal/Address/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export interface CountryFieldProps {
errorMessage: boolean | string;
onDropdownChange: (e: { target: SelectTargetObject }) => void;
readOnly?: boolean;
required?: boolean;
value: string;
}

Expand All @@ -93,6 +94,7 @@ export interface StateFieldProps {
errorMessage: boolean | string;
onDropdownChange: (e: { target: SelectTargetObject }) => void;
readOnly?: boolean;
required?: boolean;
selectedCountry: string;
specifications: Specifications;
value: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ function Select({
clearOnSelect,
blurOnClose,
onListToggle,
allowIdOnButton = false
allowIdOnButton = false,
required
}: SelectProps) {
const filterInputRef = useRef(null);
const selectContainerRef = useRef(null);
Expand Down Expand Up @@ -288,6 +289,7 @@ function Select({
disabled={disabled}
ariaDescribedBy={ariaDescribedBy}
allowIdOnButton={allowIdOnButton}
required={required}
/>
<SelectList
active={activeOption}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function SelectButtonElement({ filterable, toggleButtonRef, ...props }) {
}

function SelectButton(props: Readonly<SelectButtonProps>) {
const { active, selected, inputText, readonly, showList } = props;
const { active, selected, inputText, readonly, showList, required } = props;

// display fallback order
const displayText = selected.selectedOptionName || selected.name || props.placeholder || '';
Expand Down Expand Up @@ -88,6 +88,7 @@ function SelectButton(props: Readonly<SelectButtonProps>) {
readOnly={props.readonly}
id={props.id}
aria-describedby={props.ariaDescribedBy}
required={required}
/>
{!showList && selected.secondaryText && (
<span className="adyen-checkout__dropdown__button__secondary-text">{selected.secondaryText}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SelectProps {
onInput?: (value: string) => void;
placeholder?: string;
readonly: boolean;
required?: boolean;
selectedValue?: string | number;
uniqueId?: string;
disabled?: boolean;
Expand All @@ -55,6 +56,7 @@ export interface SelectButtonProps {
onInput: (e: Event) => void;
placeholder: string;
readonly: boolean;
required: boolean;
selectListId: string;
showList: boolean;
toggleButtonRef;
Expand Down

0 comments on commit 7833841

Please sign in to comment.