next-helios-fe 1.8.117 → 1.8.118

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-helios-fe",
3
- "version": "1.8.117",
3
+ "version": "1.8.118",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1476,6 +1476,7 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1476
1476
  }) => {
1477
1477
  const inputRef = useRef<HTMLDivElement>(null);
1478
1478
  const dropdownRef = useRef<HTMLButtonElement>(null);
1479
+ const [tempValue, setTempValue] = useState("");
1479
1480
  const [selectedCountry, setSelectedCountry] = useState("62");
1480
1481
  const [openDropdown, setOpenDropdown] = useState(false);
1481
1482
  const [dropdownWidth, setDropdownWidth] = useState<number>(0);
@@ -1497,12 +1498,38 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1497
1498
 
1498
1499
  useEffect(() => {
1499
1500
  if (rest.value) {
1501
+ setTempValue(
1502
+ (rest.value as string).replace(
1503
+ new RegExp(
1504
+ `^${
1505
+ countryPhoneCode.find((item) =>
1506
+ (rest.value as string).startsWith(item.dial_code)
1507
+ )?.dial_code
1508
+ }`
1509
+ ),
1510
+ ""
1511
+ )
1512
+ );
1513
+
1500
1514
  setSelectedCountry(
1501
1515
  countryPhoneCode.find((item) =>
1502
1516
  (rest.value as string).startsWith(item.dial_code)
1503
1517
  )?.dial_code || ""
1504
1518
  );
1505
1519
  } else if (rest.defaultValue) {
1520
+ setTempValue(
1521
+ (rest.defaultValue as string).replace(
1522
+ new RegExp(
1523
+ `^${
1524
+ countryPhoneCode.find((item) =>
1525
+ (rest.value as string).startsWith(item.dial_code)
1526
+ )?.dial_code
1527
+ }`
1528
+ ),
1529
+ ""
1530
+ )
1531
+ );
1532
+
1506
1533
  setSelectedCountry(
1507
1534
  countryPhoneCode.find((item) =>
1508
1535
  (rest.defaultValue as string).startsWith(item.dial_code)
@@ -1542,19 +1569,31 @@ export const PhoneNumber: React.FC<PhoneNumberProps> = ({
1542
1569
  <span className="text-disabled">{`+${selectedCountry}`}</span>
1543
1570
  </div>
1544
1571
  <input
1545
- type="number"
1572
+ type="text"
1546
1573
  className={`w-full ps-16 pe-4 border-default border rounded-md bg-secondary-bg [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none placeholder:duration-300 placeholder:translate-x-0 focus:placeholder:translate-x-1 placeholder:text-silent focus:outline-none focus:ring-1 focus:ring-primary focus:shadow focus:shadow-primary focus:border-primary-dark disabled:bg-secondary-light disabled:text-disabled ${height}`}
1547
1574
  placeholder="Phone number"
1548
1575
  required={rest.required}
1549
1576
  disabled={rest.disabled}
1550
- value={((rest.value || "") as string).split(selectedCountry)[1]}
1577
+ value={tempValue || ""}
1551
1578
  onChange={(e) => {
1552
- rest.onChange &&
1553
- rest.onChange({
1554
- target: {
1555
- value: `${selectedCountry}${e.target.value}`,
1556
- } as HTMLInputElement,
1557
- } as any);
1579
+ if (/^\d*$/.test(e.target.value)) {
1580
+ setTempValue(e.target.value);
1581
+
1582
+ rest.onChange &&
1583
+ rest.onChange({
1584
+ target: {
1585
+ value: `${selectedCountry}${e.target.value}`,
1586
+ } as HTMLInputElement,
1587
+ } as any);
1588
+
1589
+ if (e.target.value.startsWith(selectedCountry)) {
1590
+ e.target.setCustomValidity(
1591
+ "Please enter a valid phone number."
1592
+ );
1593
+ } else {
1594
+ e.target.setCustomValidity("");
1595
+ }
1596
+ }
1558
1597
  }}
1559
1598
  />
1560
1599
  </div>