ts-methods-action-sheet.md 3.1 KB
Newer Older
Z
zengyawen 已提交
1
# Action Sheet
Z
zengyawen 已提交
2 3


4
> **NOTE**<br>
Z
zengyawen 已提交
5
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
6

Z
zengyawen 已提交
7 8 9 10 11

An action sheet is a dialog box that displays actions a user can take.


## Required Permissions
Z
zengyawen 已提交
12 13 14

None

Z
zengyawen 已提交
15 16 17 18 19 20 21 22

## ActionSheet.show

show(options: { paramObject1})

Defines and shows the action sheet.

- paramObject1 parameters
23
  | Name | Type | Mandatory | Default Value | Description |
Z
zengyawen 已提交
24
  | -------- | -------- | -------- | -------- | -------- |
E
esterzhou 已提交
25 26 27 28 29 30 31 32
  | title | string \|[Resource](../../ui/ts-types.md#resource) | No | None | Title of the dialog box. |
  | message | string \|[Resource](../../ui/ts-types.md#resource) |  |  | Content of the dialog box. |
  | autoCancel | boolean | No | true | Whether to close the dialog box when the overlay is clicked. |
  | confirm | {<br/>value: string \|[Resource](../../ui/ts-types.md#resource),<br>action: () =&gt; void<br/>} | number | string | Text content of the confirm button and callback upon button clicking.<br/>**value**: button text.<br/>**action**: callback upon button clicking. |
  | cancel | () =&gt; void | No | - | Callback invoked when the dialog box is closed after the overlay is clicked. |
  | alignment | DialogAlignment | No | DialogAlignment.Default | Alignment mode of the dialog box in the vertical direction. |
  | offset | {<br/>dx: Length\|[Resource](../../ui/ts-types.md#resource)<br/>dy: Length\|[Resource](../../ui/ts-types.md#resource)<br/>} | No | - | Offset of the dialog box relative to the alignment position. |
  | sheets | Array&lt;SheetInfo&gt; | Yes | - | Options in the dialog box. Each option supports the image, text, and callback. |
Z
zengyawen 已提交
33 34

- SheetInfo parameters
E
esterzhou 已提交
35
  | Name | Type | Mandatory | Default Value | Description |
36
  | -------- | -------- | -------- | -------- | -------- |
E
esterzhou 已提交
37 38 39
  | title | string | Yes | - | Sheet text. |
  | icon | string | No | None | Sheet icon. |
  | action | ()=&gt;void | Yes | - | Callback when the sheet is selected. |
Z
zengyawen 已提交
40 41 42 43 44


## Example


Z
zengyawen 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

```
@Entry
@Component
struct ActionSheetExapmle {
  build() {
    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
      Button('Click to Show ActionSheet')
        .onClick(() => {
          ActionSheet.show({
            title: 'ActionSheet title',
            message: 'message',
            confirm: {
              value: 'Confirm button',
              action: () => {
                console.log('Get Alert Dialog handled')
              }
            },
            sheets: [
              {
                title: 'apples',
                action: () => {
                  console.error('apples')
                }
              },
              {
                title: 'bananas',
                action: () => {
                  console.error('bananas')
                }
              },
              {
                title: 'pears',
                action: () => {
                  console.error('pears')
                }
              }
            ]
          })
        })
    }.width('100%')
    .height('100%')
  }
}
```

Z
zengyawen 已提交
91 92

![en-us_image_0000001212058508](figures/en-us_image_0000001212058508.gif)
Z
zengyawen 已提交
93