Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mui-address-autocomplete

Package Overview
Dependencies
Maintainers
0
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mui-address-autocomplete

![GitHub package.json dependency version (prod)](https://img.shields.io/github/package-json/dependency-version/zenoo/mui-address-autocomplete/@mui/material) ![GitHub package.json dependency version (prod)](https://img.shields.io/github/package-json/depen

  • 3.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

MUI Address Autocomplete

GitHub package.json dependency version (prod) GitHub package.json dependency version (prod)

A simple, straight-forward address autocomplete component for MUI.

Demo

Installation

npm i mui-address-autocomplete

Props

interface AddressAutocompleteProps extends AutocompleteProps {
  apiKey?: string;
  fields?: string[] = ['address_components', 'formatted_address'];
  label: string;
  renderInput?: (params: AutocompleteRenderInputParams) => React.ReactNode;
  onChange: (
    event: React.SyntheticEvent<Element, Event>,
    value: AddressAutocompleteValue,
    reason: AutocompleteChangeReason
  ) => void;
  value: AddressAutocompleteValue | null;
  requestOptions?: Omit<google.maps.places.AutocompletionRequest, 'input'>;
}

Usage

import AddressAutocomplete from 'mui-address-autocomplete';

<AddressAutocomplete
  apiKey="googlePlacesApiKeyHere"
  label="Address"
  fields={['geometry']} // fields will always contain address_components and formatted_address, no need to repeat them
  onChange={(_, value) => {
    console.log(value);
  }}
/>

All of MUI's <Autocomplete> props are supported.

Result type

The result contains the fields exposed by Google Places API.
In addition, a new field components is added to the result. It contains a more easily accessible version of the address components.
You can use it like this:

value.components.street_number[0].long_name
interface AddressAutocompleteResultComponent {
  long_name: string;
  short_name: string;
}

interface AddressAutocompleteValue extends PlaceType, google.maps.places.PlaceResult {
  components: {
    administrative_area_level_1?: AddressAutocompleteResultComponent[];
    administrative_area_level_2?: AddressAutocompleteResultComponent[];
    administrative_area_level_3?: AddressAutocompleteResultComponent[];
    administrative_area_level_4?: AddressAutocompleteResultComponent[];
    administrative_area_level_5?: AddressAutocompleteResultComponent[];
    administrative_area_level_6?: AddressAutocompleteResultComponent[];
    administrative_area_level_7?: AddressAutocompleteResultComponent[];
    archipelago?: AddressAutocompleteResultComponent[];
    colloquial_area?: AddressAutocompleteResultComponent[];
    continent?: AddressAutocompleteResultComponent[];
    country?: AddressAutocompleteResultComponent[];
    establishment?: AddressAutocompleteResultComponent[];
    finance?: AddressAutocompleteResultComponent[];
    floor?: AddressAutocompleteResultComponent[];
    food?: AddressAutocompleteResultComponent[];
    general_contractor?: AddressAutocompleteResultComponent[];
    geocode?: AddressAutocompleteResultComponent[];
    health?: AddressAutocompleteResultComponent[];
    intersection?: AddressAutocompleteResultComponent[];
    landmark?: AddressAutocompleteResultComponent[];
    locality?: AddressAutocompleteResultComponent[];
    natural_feature?: AddressAutocompleteResultComponent[];
    neighborhood?: AddressAutocompleteResultComponent[];
    place_of_worship?: AddressAutocompleteResultComponent[];
    plus_code?: AddressAutocompleteResultComponent[];
    point_of_interest?: AddressAutocompleteResultComponent[];
    political?: AddressAutocompleteResultComponent[];
    post_box?: AddressAutocompleteResultComponent[];
    postal_code?: AddressAutocompleteResultComponent[];
    postal_code_prefix?: AddressAutocompleteResultComponent[];
    postal_code_suffix?: AddressAutocompleteResultComponent[];
    postal_town?: AddressAutocompleteResultComponent[];
    premise?: AddressAutocompleteResultComponent[];
    room?: AddressAutocompleteResultComponent[];
    route?: AddressAutocompleteResultComponent[];
    street_address?: AddressAutocompleteResultComponent[];
    street_number?: AddressAutocompleteResultComponent[];
    sublocality?: AddressAutocompleteResultComponent[];
    sublocality_level_1?: AddressAutocompleteResultComponent[];
    sublocality_level_2?: AddressAutocompleteResultComponent[];
    sublocality_level_3?: AddressAutocompleteResultComponent[];
    sublocality_level_4?: AddressAutocompleteResultComponent[];
    sublocality_level_5?: AddressAutocompleteResultComponent[];
    subpremise?: AddressAutocompleteResultComponent[];
    town_square?: AddressAutocompleteResultComponent[];
  };
}

More examples

Default value

const [value, setValue] = useState<AddressAutocompleteValue | null>({
  place_id: "ChIJD7fiBh9u5kcRYJSMaMOCCwQ",
  description: "Paris, France",
  components: {},
  structured_formatting: {
    main_text: "Paris",
    secondary_text: "France",
    main_text_matched_substrings: []
  }
});

return (
  <AddressAutocomplete
    apiKey="googlePlacesApiKeyHere"
    label="Address"
    onChange={(_, value) => {
      setValue(value);
    }}
    value={value}
  />
);

Keywords

FAQs

Package last updated on 28 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc