npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mmerlone/mui7-phone-number

v2.0.4

Published

Phone number input component compatible with MUI v7

Downloads

616

Readme

@mmerlone/mui7-phone-number

npm version npm downloads License: MIT

A phone number input component for MUI v7+ with auto-formatting, country selection, and full TypeScript support.

Built on top of @mui/material/TextField, rendering a country flag selector as a start adornment alongside the formatted phone input.

This is a fork of mui-phone-number updated to support MUI v7, React 19, and modern TypeScript.

Sample

Live Demo

Requirements

  • React 19+
  • @mui/material v7+

Installation

npm install @mmerlone/mui7-phone-number
# or
pnpm add @mmerlone/mui7-phone-number

Usage

Uncontrolled

import MuiPhoneNumber from '@mmerlone/mui7-phone-number';

function MyForm() {
  return (
    <MuiPhoneNumber
      defaultCountry="us"
      onChange={(value, country) => {
        console.log(value);   // e.g. "+1 (702) 123-4567"
        console.log(country); // { name, dialCode, countryCode }
      }}
    />
  );
}

Controlled

import { useState } from 'react';
import MuiPhoneNumber from '@mmerlone/mui7-phone-number';

function MyForm() {
  const [phone, setPhone] = useState('');

  return (
    <MuiPhoneNumber
      defaultCountry="us"
      value={phone}
      onChange={(value) => setPhone(value)}
    />
  );
}

Props

Country selection

| Prop | Type | Default | Description | |---|---|---|---| | defaultCountry | string | "" | Initial country (ISO 3166-1 alpha-2, e.g. "us") | | onlyCountries | string[] | — | Restrict to these country codes | | excludeCountries | string[] | — | Exclude these country codes | | preferredCountries | string[] | — | Pin these countries to the top of the dropdown | | regions | string \| string[] | — | Filter by region or subregion (see Regions) |

Input behaviour

| Prop | Type | Default | Description | |---|---|---|---| | value | string | — | Controlled value | | placeholder | string | "+1 (702) 123-4567" | Input placeholder | | autoFormat | boolean | true | Auto-format the number as the user types | | disableAreaCodes | boolean | false | Disable area code sub-entries | | disableCountryCode | boolean | false | Hide the dial code prefix in the input | | disableDropdown | boolean | false | Render the flag without a clickable dropdown | | enableLongNumbers | boolean | false | Allow numbers longer than the country format | | countryCodeEditable | boolean | true | Allow the user to edit the country code portion | | localization | Record<string, string> | — | Override country display names (e.g. { Germany: 'Deutschland' }) | | native | boolean | false | Use a native <select> for the country dropdown |

Validation

| Prop | Type | Description | |---|---|---| | error | boolean | Force error state on the TextField | | isValid | (inputNumber: string) => boolean | Custom validation — receives the raw digits. The field shows an error when this returns false |

TextField passthrough

MuiPhoneNumber extends TextFieldProps (minus internally-managed keys), so standard MUI TextField props like label, helperText, fullWidth, className, sx, size, color, name, id, required, variant, disabled, and placeholder are forwarded automatically.

Additional phone-specific layout props:

| Prop | Type | Description | |---|---|---| | dropdownClass | string | Class name applied to the country dropdown container | | slotProps | { input?, htmlInput? } | MUI v7 slotProps forwarded to the TextField | | inputRef | Ref<HTMLInputElement> | Ref forwarded to the underlying <input> element |

Events

| Prop | Signature | Notes | |---|---|---| | onChange | (value: string, country: CountryData) => void | Fires on every input change | | onFocus | (event, country: CountryData) => void | — | | onBlur | (event, country: CountryData) => void | — | | onClick | (event, country: CountryData) => void | — |

The CountryData object shape:

interface CountryData {
  name: string;
  dialCode: string;
  countryCode: string; // ISO 3166-1 alpha-2
}

Exports

The package exports the default component and two useful types:

import MuiPhoneNumber from '@mmerlone/mui7-phone-number';
import type { PhoneNumberProps, CountryData } from '@mmerlone/mui7-phone-number';

Regions

Pass a single string or an array to regions to restrict the country list.

Regions: 'america' · 'europe' · 'asia' · 'oceania' · 'africa'

Subregions: 'north-america' · 'south-america' · 'central-america' · 'caribbean' · 'european-union' · 'ex-ussr' · 'middle-east' · 'north-africa'

// Single region
<MuiPhoneNumber defaultCountry="it" regions="europe" />

// Multiple subregions
<MuiPhoneNumber defaultCountry="ca" regions={['north-america', 'caribbean']} />

Localization

<MuiPhoneNumber
  onlyCountries={['de', 'es']}
  localization={{ Germany: 'Deutschland', Spain: 'España' }}
/>

Ref forwarding

The component forwards its ref to the MUI TextField root <div>. Use inputRef to access the underlying <input> element.

const inputRef = useRef<HTMLInputElement>(null);

<MuiPhoneNumber defaultCountry="us" inputRef={inputRef} />

License

MIT

Based on material-ui-phone-number, react-phone-input-2, react-phone-input and mui-phone-number.