# @digitransit-component/digitransit-component-autosuggest 中文文档

规范地址：https://npmcn.com/package/%40digitransit-component/digitransit-component-autosuggest/

版本：11\.0\.9
npm 元数据更新时间：2026-11-11T07:27:34.737Z
中文译文更新时间：2026-11-12T09:20:35.185Z
软件包许可：\(AGPL-3\.0 OR EUPL-1\.2\)

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40digitransit-component/digitransit-component-autosuggest
原文对照：https://npmcn.com/package/%40digitransit-component/digitransit-component-autosuggest/?lang=original
项目主页：https://github.com/HSLdevcom/digitransit-ui#readme
源码仓库：https://github.com/HSLdevcom/digitransit-ui

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：4 MB，10 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：5 个
- peer 依赖：luxon ^3\.7\.2，react ^18\.3\.1，i18next ^22\.5\.1，downshift ^9\.4\.0，classnames ^2\.5\.1，prop-types ^15\.8\.1，react-modal ^3\.16\.3，@hsl-fi/sass ^1\.0\.0，react-i18next ^12\.3\.1，@digitransit-component/digitransit-component-icon ^5\.0\.5，@digitransit-component/digitransit-component-dialog-modal ^7\.0\.7，@digitransit-component/digitransit-component-suggestion-item ^6\.0\.5
- 首次发布：2020-04-29T12:22:27.911Z
- 最新版本发布：2026-11-11T07:27:34.334Z
- 近 30 天下载量：3299（2026-10-12 至 2026-11-10，npm 官方下载统计）
- 已发布版本数：227（近 12 个月 49 个）

## 中文简介

digitransit 组件自动建议模块

## 安装

```sh
npm install @digitransit-component/digitransit-component-autosuggest
```

也可以使用：`pnpm add @digitransit-component/digitransit-component-autosuggest`、`yarn add @digitransit-component/digitransit-component-autosuggest`、`bun add @digitransit-component/digitransit-component-autosuggest`

## README

# @ digitalransit- 组件/ digitalransit- 组件- 自动调试

## 获取新目标

取出目标,并根据自己的位置和位置加以修改

### 参数

-   `props` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
    
    -   `props.targets` **[阵列](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)\> 翻译:**
    -   `props.isLocationSearch` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
    -   `props.isMobile` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
    -   `props.ownPlaces` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
    -   `props.sources` **[阵列](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)\> 翻译:**

回返 **[阵列](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)\> 翻译:** 新目标

## DTAUTUSUGEST 软件

自动推荐搜索输入查找地点、站点、站站、路线和车辆租赁站.

### 参数

-   `props` **DTAutosugest 方案**
    
    -   `props.sources` **[阵列](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)\> 翻译:** (可选,默认) `[]`(中文(简体) )
    -   `props.pathOpts` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (可选,默认) `{routesPrefix:'linjat',stopsPrefix:'pysakit'}`(中文(简体) )
    -   `props.refPoint` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** (可选,默认) `{}`(中文(简体) )
    -   `props.appElement`
    -   `props.id`
    -   `props.placeholder`
    -   `props.onSelect`
    -   `props.icon`
    -   `props.value` (可选,默认) `''`(中文(简体) )
    -   `props.onClear`
    -   `props.lang` (可选,默认) `'fi'`(中文(简体) )
    -   `props.getAutoSuggestIcons`
    -   `props.handleViaPoints`
    -   `props.focusChange`
    -   `props.storeRef`
    -   `props.isMobile` (可选,默认) `false`(中文(简体) )
    -   `props.mobileLabel`
    -   `props.inputClassName` (可选,默认) `''`(中文(简体) )
    -   `props.translatedPlaceholder`
    -   `props.required` (可选,默认) `false`(中文(简体) )
    -   `props.ariaLabel`
    -   `props.colors` (可选,默认) `defaultColors`(中文(简体) )
    -   `props.modeSet`
    -   `props.showScroll` (可选,默认) `false`(中文(简体) )
    -   `props.isEmbedded` (可选,默认) `false`(中文(简体) )
    -   `props.transportMode`
    -   `props.targets`
    -   `props.geocodingSize`
    -   `props.filterResults`
    -   `props.searchContext`

### 属性

-   `appElement` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
-   `id` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
-   `placeholder` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
-   `onSelect` **[函数](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**
-   `icon` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `value` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `onClear` **[函数](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)? 吗?**
-   `lang` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `getAutoSuggestIcons` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)? 吗?**
-   `handleViaPoints` **[函数](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)? 吗?**
-   `focusChange` **[函数](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)? 吗?**
-   `storeRef` **[函数](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)? 吗?**
-   `isMobile` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)? 吗?**
-   `mobileLabel` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `inputClassName` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `translatedPlaceholder` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `required` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)? 吗?**
-   `colors` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)? 吗?**
-   `modeSet` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `showScroll` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)? 吗?**
-   `isEmbedded` **[布尔](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)? 吗?** 地理编码相关道具
-   `searchContext` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
-   `transportMode` **[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 吗?**
-   `targets` **[阵列](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 说?**
-   `sources` **[阵列](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[字符串](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)? 说?**
-   `geocodingSize` **[编号](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)? 吗?**
-   `filterResults` **[函数](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)? 吗?**
-   `pathOpts` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)? 吗?**
-   `refPoint` **[对象](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)? 吗?**

### 实例

```javascript
const searchContext = {
  isPeliasLocationAware: false // true / false does Let Pelias suggest based on current user location
  minimalRegexp: undefined // used for testing min. regexp. For example: new RegExp('.{2,}'),
  lineRegexp: undefined //  identify searches for route numbers/labels: bus | train | metro. For example: new RegExp(
   //   '(^[0-9]+[a-z]?$|^[yuleapinkrtdz]$|(^m[12]?b?$))',
   //  'i',
   //  ),
  URL_PELIAS: '' // url for pelias searches
  feedIDs: ['HSL', 'HSLLautta'] // FeedId's like  [HSL, HSLLautta]
  geocodingSources: ['oa','osm','nlsfi']  // sources for geocoding
  geocodingSearchParams; {}  // Searchparmas fro geocoding
  getFavouriteLocations: () => ({}),    // Function that returns array of favourite locations.
  getFavouriteStops: () => ({}),        // Function that returns array of favourite stops.
  getLanguage: () => ({}),              // Function that returns current language.
  getFavouriteRoutes: () => ({}),       // Function that returns array of favourite routes.
  getPositions: () => ({}),             // Function that returns user's geolocation.
  getRoutesQuery: () => ({}),           // Function that returns query for fetching routes.
  getStopAndStationsQuery: () => ({}),  // Function that fetches favourite stops and stations from graphql API.
  getFavouriteRoutesQuery: () => ({}),  // Function that returns query for fetching favourite routes.
  getFavouriteVehicleRentalStations: () => ({}),  // Function that returns favourite bike rental station.
  getFavouriteVehicleRentalStationsQuery: () => ({}), // Function that returns query for fetching favourite bike rental stations.
  getHasOtpLocationFavourites: () => ({}), // Optional. Function that returns whether any OTP-backed favourite is currently available.
  startLocationWatch: () => ({}),       // Function that locates users geolocation.
  saveSearch: () => ({}),               // Function that saves search to old searches store.
  clearOldSearches: () => ({}),         // Function that clears old searches store.
  getFutureRoutes: () => ({}),          // Function that return future routes
  saveFutureRoute: () => ({}),          // Function that saves a future route
  clearFutureRoutes: () => ({}),        // Function that clears future routes
};
const lang = 'fi'; // en, fi or sv
const onSelect = (item, id) => {
   // Funtionality when user selects a suggesions. No default implementation is given.
   return null;
};
const onClear = id => {
   // Called  when user clicks the clear search string button. No default implementation.
   return null;
};
const getAutoSuggestIcons: {
  // Called for every city bike station rendered as a search suggestion. Should return the icon and
  // color used for that station. Two icons are available, 'citybike-stop-digitransit' anditybike-stop-digitransit-secondary'.
  citybikes: station => {
     return ['citybike-stop-digitransit', '#f2b62d'];
  }
}
const transportMode = undefined;
const placeholder = "stop-near-you";
const targets = ['Locations', 'Stops', 'Routes']; // Defines what you are searching. Options are Locations, Stops, Stations, Routes, VehicleRentalStations, FutureRoutes, MapPosition and CurrentPosition. Leave empty to search all targets.
const sources = ['Favourite', 'History', 'Datasource'] // Defines where you are searching. all available are: Favourite, History (previously searched searches) and Datasource. Leave empty to use all sources.
return (
 <DTAutosuggest
   appElement={appElement} // Required. Root element's id. Needed for react-modal component.
   searchContext={searchContext}
   icon="origin" // Optional String for icon that is shown left of searchfield. used with Icon library
   id="origin" // used for style props and info for component.
   placeholder={placeholder} // String that is showns initally in search field
   value="" // e.g. user typed string that is shown in search field
   onSelect={onSelect}
   onClear={onClear}
   lang={lang}
   getAutoSuggestIcons={getAutoSuggestIcons}
   transportMode={transportMode} // transportmode with which we filter the routes, e.g. route-BUS
   geocodingSize={10} // defines how many stops and stations to fetch from geocoding. Useful if you want to filter the results and still get a reasonable amount of suggestions.
   filterResults={results => return results} // Optional filtering function for routes and stops
   handelViaPoints={() => return null } // Optional Via point handling logic. This is currently managed with DTAutosuggestpanel by default, but if DTAutosuggest is used seperatelly own implementation must be provided.
   focusChange={() => return null} // When suggestion is selected, handle changing focus. This is currently managed with DTAutosuggestpanel by default, but if DTAutosuggest is used seperatelly own implementation must be provided.
   storeRef={() => return null} // Functionality to store refs. Currenlty managed with DTAutosuggestpanel by default, but if DTAutosuggest is used seperatelly own implementation must be provided.
   sources={sources}
   targets={targets}
   isMobile  // Optional. Defaults to false. Whether to use mobile search.
   mobileLabel="Custom label" // Optional. Custom label text for autosuggest field on mobile.
   inputClassName="" // Optional. Custom classname applied to the input element of the component for providing CSS styles.
   translatedPlaceholder= // Optional. Custon translated placeholder text for autosuggest field.
```

回返 **联合来文十。 元素**

\-- -- . .

这个模块是Digitransit-ui项目的一部分. 保留在 [HSLdevcom/数码-i](https://github.com/HSLdevcom/digitransit-ui) 库,您可以创建的地方 公关和问题.

### 安装

单独安装此模块 :

```sh
$ npm install @digitransit-component/digitransit-component-autosuggest
```

## 常见问题

### @digitransit-component/digitransit-component-autosuggest 是什么？

digitransit 组件自动建议模块

### 如何安装 @digitransit-component/digitransit-component-autosuggest？

在项目目录运行 npm install @digitransit-component/digitransit-component-autosuggest，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：luxon（^3\.7\.2）、react（^18\.3\.1）、i18next（^22\.5\.1）、downshift（^9\.4\.0）、classnames（^2\.5\.1）、prop-types（^15\.8\.1）、react-modal（^3\.16\.3）、@hsl-fi/sass（^1\.0\.0）、react-i18next（^12\.3\.1）、@digitransit-component/digitransit-component-icon（^5\.0\.5）、@digitransit-component/digitransit-component-dialog-modal（^7\.0\.7）、@digitransit-component/digitransit-component-suggestion-item（^6\.0\.5）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @digitransit-component/digitransit-component-autosuggest 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/digitransit-component\_\_digitransit-component-autosuggest 是否存在。

### @digitransit-component/digitransit-component-autosuggest 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @digitransit-component/digitransit-component-autosuggest 可以商用吗？

@digitransit-component/digitransit-component-autosuggest 使用 \(AGPL-3\.0 OR EUPL-1\.2\) 许可。可在 AGPL-3\.0、EUPL-1\.2 中任选其一遵守。以上为概括，不构成法律意见，请以许可原文为准。

### @digitransit-component/digitransit-component-autosuggest 的下载量有多少？

根据 npm 官方下载统计，@digitransit-component/digitransit-component-autosuggest 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,299 次，日均约 110 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @digitransit-component/digitransit-component-autosuggest 还在维护吗？

最新版本 11\.0\.9 发布于 2026/11/11（1 天前）；至今共发布 227 个版本，其中过去 12 个月发布了 49 个；首次发布于 2020/04/29。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

