Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Как вывести вывод результата только города? #173

Open
DanisKhasanov opened this issue Nov 21, 2024 · 0 comments

Comments

@DanisKhasanov
Copy link

import { forwardRef } from "react";
import { AddressSuggestions } from "react-dadata";
import { Box, OutlinedInput, styled } from "@mui/material";

const apiKey = import.meta.env.VITE_DADATA_API_KEY;

const StyledInput = styled(OutlinedInput)({
  fontSize: "14px",
  padding: "0px",
  border: "none",
});

const Address = forwardRef<
  HTMLInputElement,
  { onChange: (event: { target: { value: string } }) => void }
>(({ onChange }, ref) => {
  return (
    <AddressSuggestions
      token={apiKey}
      onChange={(suggestion) =>
        onChange({ target: { value: suggestion?.value || "" } })
      }
      inputProps={{
        placeholder: "Город отгрузки",
        required: true,
      }}
      customInput={StyledInput}
    />
  );
});

export default function Autocomplete() {
  const handleAddressChange = (event: { target: { value: string } }) => {
    console.log("город:", event.target.value);
  };

  return (
    <Box sx={{ mt: 1 }}>
      <Address onChange={handleAddressChange} />
    </Box>
  );
}

Есть такой компонент, как вывести не весь адрес, а только город?
Кстати, этот компонент использует стили MUI TextField, если кому вдруг необходимо.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant