Skip to content

Commit

Permalink
chore: fix format errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ybrusentsov committed Jan 15, 2024
1 parent edd3bc2 commit c35a266
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
19 changes: 15 additions & 4 deletions src/components/CountrySelector/CountrySelectorDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import './CountrySelectorDropdown.style.scss';

import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';

import { defaultCountries } from '../../data/countryData';
import { buildClassNames } from '../../style/buildClassNames';
Expand Down Expand Up @@ -108,7 +114,9 @@ export const CountrySelectorDropdown: React.FC<

const getCountryIndex = useCallback(
(country: CountryIso2) => {
return orderedCountries.findIndex((c) => parseCountry(c).iso2 === country);
return orderedCountries.findIndex(
(c) => parseCountry(c).iso2 === country,
);
},
[orderedCountries],
);
Expand Down Expand Up @@ -200,7 +208,9 @@ export const CountrySelectorDropdown: React.FC<
const scrollToFocusedCountry = useCallback(() => {
if (!listRef.current || focusedItemIndex === undefined) return;

const focusedCountry = parseCountry(orderedCountries[focusedItemIndex]).iso2;
const focusedCountry = parseCountry(
orderedCountries[focusedItemIndex],
).iso2;
if (focusedCountry === lastScrolledCountry.current) return;

const element = listRef.current.querySelector(
Expand Down Expand Up @@ -268,7 +278,8 @@ export const CountrySelectorDropdown: React.FC<
className={buildClassNames({
addPrefix: [
'country-selector-dropdown__list-item',
preferredCountrySet.has(country.iso2) && 'country-selector-dropdown__list-item--preferred',
preferredCountrySet.has(country.iso2) &&
'country-selector-dropdown__list-item--preferred',
isSelected && 'country-selector-dropdown__list-item--selected',
isFocused && 'country-selector-dropdown__list-item--focused',
],
Expand Down
24 changes: 11 additions & 13 deletions src/components/PhoneInput/PhoneInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -900,24 +900,22 @@ describe('PhoneInput', () => {

describe('preferred countries', () => {
test('should display preferred countries on top', () => {
render(
<PhoneInput
preferredCountries={['us', 'gb']}
/>,
);
render(<PhoneInput preferredCountries={['us', 'gb']} />);

expect(getCountrySelectorDropdown().childNodes[0]).toBe(getDropdownOption('us'));
expect(getCountrySelectorDropdown().childNodes[1]).toBe(getDropdownOption('gb'));
expect(getCountrySelectorDropdown().childNodes[0]).toBe(
getDropdownOption('us'),
);
expect(getCountrySelectorDropdown().childNodes[1]).toBe(
getDropdownOption('gb'),
);
});

test('should ignore invalid preferred countries', () => {
render(
<PhoneInput
preferredCountries={['xxx', 'us']}
/>,
);
render(<PhoneInput preferredCountries={['xxx', 'us']} />);

expect(getCountrySelectorDropdown().childNodes[0]).toBe(getDropdownOption('us'));
expect(getCountrySelectorDropdown().childNodes[0]).toBe(
getDropdownOption('us'),
);
});
});

Expand Down

0 comments on commit c35a266

Please sign in to comment.