1e41f4b71Sopenharmony_ci# popup
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci>  **NOTE**
4e41f4b71Sopenharmony_ci>
5e41f4b71Sopenharmony_ci>  This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci The **\<popup>** component is used to display a pop-up to offer instructions after a user clicks a bound component or calls the specific API.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Required Permissions
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciNone
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## Child Components
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ciThis component supports only one child component.<sup>5+</sup>
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## Attributes
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciIn addition to the [universal attributes](js-components-common-attributes.md), the following attributes are supported.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
24e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
25e41f4b71Sopenharmony_ci| target | string | - | Yes| ID of the target element. Dynamic switch is not supported.|
26e41f4b71Sopenharmony_ci| placement | string | bottom | No| Position of the pop-up relative to the target element. Available values are as follows:<br>- **left**: on the left of the target element.<br>- **right**: on the right of the target element.<br>- **top**: at the top of the target element;<br>- **bottom**: at the bottom of the target element.<br>- **topLeft**: in the upper left corner of the target element.<br>- **topRight**: in the upper right corner of the target element.<br>- **bottomLeft**: in the lower left corner of the target element.<br>- **bottomRight**: in the lower right corner of the target element.|
27e41f4b71Sopenharmony_ci| keepalive<sup>5+</sup> | boolean | false | No| Whether to retain this pop-up. **true**: The pop-up does not disappear when users tap other areas or switch the page. To hide the pop-up, call the **hide** method.<br>**false**: The pop-up disappears when users tap other areas or switch the page.|
28e41f4b71Sopenharmony_ci| clickable<sup>5+</sup> | boolean | true | No| Whether to display the pop-up when the user clicks the target element. If this attribute is set to **false**, the pop-up can be triggered only by an API call.|
29e41f4b71Sopenharmony_ci| arrowoffset<sup>5+</sup> | &lt;length&gt; | 0 | No| Offset of the pop-up arrow. By default, the arrow is centered. A positive value means that the arrow moves along the language direction (LTR or RTL), and a negative value means that the arrow moves along the opposite direction of the language direction.|
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci>  **NOTE**
32e41f4b71Sopenharmony_ci>
33e41f4b71Sopenharmony_ci> The **focusable** attribute is not supported.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci## Styles
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ciIn addition to the [universal styles](js-components-common-styles.md), the following styles are supported.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
41e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
42e41f4b71Sopenharmony_ci| mask-color | &lt;color&gt; | - | No| Color configuration of the mask layer. By default, the mask layer is completely transparent.|
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci>  **NOTE**
45e41f4b71Sopenharmony_ci>
46e41f4b71Sopenharmony_ci> Position-related styles are not supported.
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci## Events
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ciIn addition to the [universal events](js-components-common-events.md), the following events are supported.
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci| Name| Parameter| Description|
54e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
55e41f4b71Sopenharmony_ci| visibilitychange | { visibility: boolean } | Triggered when a pop-up appears or disappears.|
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci## Methods
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ciThe following methods are supported.
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci| Name| Parameter| Description|
63e41f4b71Sopenharmony_ci| -------- | -------- | -------- |
64e41f4b71Sopenharmony_ci| show<sup>5+</sup> | - | Shows the pop-up.|
65e41f4b71Sopenharmony_ci| hide<sup>5+</sup> | - | Hides the pop-up.|
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci>  **NOTE**
68e41f4b71Sopenharmony_ci> 1. Attributes and styles of a **\<popup>** component cannot be dynamically updated.
69e41f4b71Sopenharmony_ci> 
70e41f4b71Sopenharmony_ci> 2. Margins of a pop-up take effect depending on its position relative to the target element. For example, if the pop-up is below the target element, only **margin-top** takes effect; if the pop-up displays on the upper left of the target element, only **margin-bottom** and **margin-right** take effect.
71e41f4b71Sopenharmony_ci> 
72e41f4b71Sopenharmony_ci> 3. Styles set for the four borders of a pop-up must be the same. If they are different and the border radius is **0**, the first configured border style (in the sequence of left, top, right, and bottom) takes effect. Otherwise, the **border** attribute does not take effect.
73e41f4b71Sopenharmony_ci> 
74e41f4b71Sopenharmony_ci> 4. The click event bound to the target element of a pop-up does not take effect.
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci## Example
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci```html
80e41f4b71Sopenharmony_ci<!-- xxx.hml -->
81e41f4b71Sopenharmony_ci<div class="container">
82e41f4b71Sopenharmony_ci  <text id="text">Click to show the pop-up</text>
83e41f4b71Sopenharmony_ci  <!-- popup supports single child of any type5+ -->
84e41f4b71Sopenharmony_ci  <popup id="popup" class="popup" target="text" placement="top" keepalive="true" clickable="true" 
85e41f4b71Sopenharmony_ci    arrowoffset="100px" onvisibilitychange="visibilitychange" onclick="hidepopup">
86e41f4b71Sopenharmony_ci    <text class="text">Text content of the pop-up</text>
87e41f4b71Sopenharmony_ci  </popup>
88e41f4b71Sopenharmony_ci  <button class="button" onclick="showpopup">Click to show the pop-up</button>
89e41f4b71Sopenharmony_ci</div>
90e41f4b71Sopenharmony_ci```
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```css
93e41f4b71Sopenharmony_ci/* xxx.css */
94e41f4b71Sopenharmony_ci.container {
95e41f4b71Sopenharmony_ci  flex-direction: column;
96e41f4b71Sopenharmony_ci  align-items: center;
97e41f4b71Sopenharmony_ci  padding-top: 200px;
98e41f4b71Sopenharmony_ci}
99e41f4b71Sopenharmony_ci.popup {
100e41f4b71Sopenharmony_ci  mask-color: gray;
101e41f4b71Sopenharmony_ci}
102e41f4b71Sopenharmony_ci.text {
103e41f4b71Sopenharmony_ci  color: white;
104e41f4b71Sopenharmony_ci}
105e41f4b71Sopenharmony_ci.button {
106e41f4b71Sopenharmony_ci  width: 220px;
107e41f4b71Sopenharmony_ci  height: 70px;
108e41f4b71Sopenharmony_ci  margin-top: 50px;
109e41f4b71Sopenharmony_ci}
110e41f4b71Sopenharmony_ci```
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci```js
113e41f4b71Sopenharmony_ci// xxx.js
114e41f4b71Sopenharmony_ciimport promptAction from '@ohos.promptAction'
115e41f4b71Sopenharmony_ciexport default {
116e41f4b71Sopenharmony_ci  visibilitychange(e) {
117e41f4b71Sopenharmony_ci    promptAction.showToast({
118e41f4b71Sopenharmony_ci      message: 'visibility change visibility: ' + e.visibility,
119e41f4b71Sopenharmony_ci        duration: 3000
120e41f4b71Sopenharmony_ci    }); 
121e41f4b71Sopenharmony_ci  },
122e41f4b71Sopenharmony_ci  showpopup() {
123e41f4b71Sopenharmony_ci    this.$element("popup").show();
124e41f4b71Sopenharmony_ci  },
125e41f4b71Sopenharmony_ci  hidepopup() {
126e41f4b71Sopenharmony_ci    this.$element("popup").hide();
127e41f4b71Sopenharmony_ci  }
128e41f4b71Sopenharmony_ci}
129e41f4b71Sopenharmony_ci```
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci![en-us_image_0000001178886129](figures/en-us_image_0000001178886129.png)
132