diff --git a/docs/en-US/component/image.md b/docs/en-US/component/image.md index 684d80a1a9..b07366ed47 100644 --- a/docs/en-US/component/image.md +++ b/docs/en-US/component/image.md @@ -51,19 +51,20 @@ image/image-preview ### Image Attributes -| Name | Description | Type | Default | -| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------- | -| `src` | image source, same as native. | `string` | — | -| `fit` | indicate how the image should be resized to fit its container, same as [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit). | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale'-down'` | — | -| `hide-on-click-modal` | when enabling preview, use this flag to control whether clicking on backdrop can exit preview mode. | `boolean` | `false` | -| `lazy` | whether to use lazy load. | `boolean` | `false` | -| `scroll-container` | the container to add scroll listener when using lazy load. | `string \| HTMLElement` | the nearest parent container whose overflow property is auto or scroll. | -| `alt` | native attribute `alt`. | `string` | — | -| `referrer-policy` | native attribute `referrerPolicy`. | `string` | — | -| `preview-src-list` | allow big image preview. | `string[]` | — | -| `z-index` | set image preview z-index. | `number` | — | -| `initial-index` | initial preview image index, less than the length of `url-list`. | `number` | `0` | -| `preview-teleported` | whether to append image-viewer to body. A nested parent element attribute transform should have this attribute set to `true`. | `boolean` | `false` | +| Name | Description | Type | Default | +| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------------------- | +| `src` | image source, same as native. | `string` | — | +| `fit` | indicate how the image should be resized to fit its container, same as [object-fit](https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit). | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale'-down'` | — | +| `hide-on-click-modal` | when enabling preview, use this flag to control whether clicking on backdrop can exit preview mode. | `boolean` | `false` | +| `lazy` | whether to use lazy load. | `boolean` | `false` | +| `scroll-container` | the container to add scroll listener when using lazy load. | `string \| HTMLElement` | the nearest parent container whose overflow property is auto or scroll. | +| `alt` | native attribute `alt`. | `string` | — | +| `referrer-policy` | native attribute `referrerPolicy`. | `string` | — | +| `preview-src-list` | allow big image preview. | `string[]` | — | +| `z-index` | set image preview z-index. | `number` | — | +| `initial-index` | initial preview image index, less than the length of `url-list`. | `number` | `0` | +| `close-on-press-escape` | whether the image-viewer can be closed by pressing ESC | `boolean` | `true` | +| `preview-teleported` | whether to append image-viewer to body. A nested parent element attribute transform should have this attribute set to `true`. | `boolean` | `false` | ### Image Events diff --git a/packages/components/image-viewer/src/image-viewer.ts b/packages/components/image-viewer/src/image-viewer.ts index 0bcc8d3226..093e29e69a 100644 --- a/packages/components/image-viewer/src/image-viewer.ts +++ b/packages/components/image-viewer/src/image-viewer.ts @@ -31,6 +31,10 @@ export const imageViewerProps = buildProps({ type: Boolean, default: false, }, + closeOnPressEscape: { + type: Boolean, + default: true, + }, } as const) export type ImageViewerProps = ExtractPropTypes diff --git a/packages/components/image-viewer/src/image-viewer.vue b/packages/components/image-viewer/src/image-viewer.vue index 428faade30..290f5e8e73 100644 --- a/packages/components/image-viewer/src/image-viewer.vue +++ b/packages/components/image-viewer/src/image-viewer.vue @@ -212,7 +212,7 @@ function registerEventListener() { switch (e.code) { // ESC case EVENT_CODE.esc: - hide() + props.closeOnPressEscape && hide() break // SPACE case EVENT_CODE.space: diff --git a/packages/components/image/src/image.ts b/packages/components/image/src/image.ts index 4fa5f04069..fbc0fd645f 100644 --- a/packages/components/image/src/image.ts +++ b/packages/components/image/src/image.ts @@ -51,6 +51,10 @@ export const imageProps = buildProps({ type: Boolean, default: true, }, + closeOnPressEscape: { + type: Boolean, + default: true, + }, } as const) export type ImageProps = ExtractPropTypes diff --git a/packages/components/image/src/image.vue b/packages/components/image/src/image.vue index 6366093c8a..da92f309e8 100644 --- a/packages/components/image/src/image.vue +++ b/packages/components/image/src/image.vue @@ -23,6 +23,7 @@ :url-list="previewSrcList" :hide-on-click-modal="hideOnClickModal" :teleported="teleported" + :close-on-press-escape="closeOnPressEscape" @close="closeViewer" @switch="switchViewer" >