Action Sheet

    Action Sheet is a slide-up pane for presenting the user with a set of alternatives for how to proceed with a given task.

    You can also use action sheets to prompt the user to confirm a potentially dangerous action.

    The action sheet contains an optional title and one or more buttons, each of which corresponds to an action to take.

    Note that it is not recommended to use Action Sheet on large screens (iPad). On large screens you should use Popover instead.

    Lets look at related App methods to work with the Action Sheet:

    app.actions.create(parameters)- create Action Sheet instance

    • parameters - object. Object with action sheet parameters

    Method returns created Action Sheet’s instance

    app.actions.destroy(el)- destroy Action Sheet instance

    • el - HTMLElement or string (with CSS Selector) or object. Action element instance to destroy.
    • el - HTMLElement or string (with CSS Selector). Action Sheet element.

    Method returns Action Sheet’s instance

    app.actions.open(el, animate)- opens Action Sheet

    • el - HTMLElement or string (with CSS Selector). Action Sheet element to open.
    • animate - boolean. Open Actions Sheet with animation.

    Method returns Action Sheet’s instance

    app.actions.close(el, animate)- closes Action Sheet

    • el - HTMLElement or string (with CSS Selector). Action Sheet element to close.
    • animate - boolean. Close Actions Sheet with animation.

    Method returns Action Sheet’s instance

    Action Sheet Parameters

    Now lets look at a list of available parameters we need to create the Action Sheet:

    Note that all of the following parameters can be used in the global app parameters under the actions property to set defaults for all action sheets. For example:

    1. var app = new Framework7({
    2. actions: {
    3. convertToPopover: false,
    4. grid: true,
    5. }
    6. });

    Each Button in buttons array must be presented as an object with button parameters:

    After that we have its initialized instance (like actions variable in example above) with useful methods and properties:

    Control Action Sheet With Links

    It is possible to open and close required action sheets (if you have them in DOM) using special classes and data attributes on links:

    • To open action sheet we need to add “actions-open“ class to any HTML element (prefered to link)

    • To close action sheet we need to add “actions-close“ class to any HTML element (prefered to link)

    • If you have more than one action sheet in DOM, you need to specify appropriate action sheet via additional data-actions=”.my-actions” attribute on this HTML element

    According to above note:

    1. <!-- In data-actions attribute we specify CSS selector of action sheet we need to open -->
    2. <p><a href="#" data-actions=".my-actions" class="actions-open">Open Actions</a></p>
    3. <!-- And somewhere in DOM -->
    4. <div class="actions-modal my-actions">
    5. ...
    6. </div>

    Action sheet will fire the following DOM events on action sheet element and events on app and action sheet instance:

    Action Sheet instance emits events on both self instance and app instance. App instance events has same names prefixed with actions.

    Examples

    1. var app = new Framework7();
    2. var $$ = Dom7;
    3. //- One group, three buttons
    4. var ac1 = app.actions.create({
    5. buttons: [
    6. {
    7. text: 'Button1',
    8. bold: true
    9. },
    10. {
    11. text: 'Button2'
    12. },
    13. {
    14. text: 'Cancel',
    15. color: 'red'
    16. },
    17. ]
    18. })
    19. //- One group, title, three buttons
    20. var ac2 = app.actions.create({
    21. buttons: [
    22. {
    23. text: 'Do something',
    24. label: true
    25. },
    26. {
    27. text: 'Button1',
    28. bold: true
    29. },
    30. {
    31. text: 'Button2',
    32. },
    33. {
    34. text: 'Cancel',
    35. },
    36. ]
    37. });
    38. //- Two groups
    39. var ac3 = app.actions.create({
    40. // First group
    41. [
    42. {
    43. text: 'Do something',
    44. label: true
    45. },
    46. {
    47. text: 'Button1',
    48. bold: true
    49. },
    50. {
    51. text: 'Button2',
    52. }
    53. ],
    54. // Second group
    55. [
    56. {
    57. text: 'Cancel',
    58. color: 'red'
    59. }
    60. ]
    61. ]
    62. });
    63. //- Three groups
    64. var ac4 = app.actions.create({
    65. buttons: [
    66. [
    67. {
    68. text: 'Share',
    69. label: true
    70. },
    71. {
    72. text: 'Mail',
    73. },
    74. {
    75. text: 'Messages',
    76. }
    77. ],
    78. [
    79. {
    80. text: 'Social share',
    81. label: true
    82. },
    83. {
    84. text: 'Facebook',
    85. },
    86. {
    87. text: 'Twitter',
    88. }
    89. ],
    90. [
    91. {
    92. text: 'Cancel',
    93. color: 'red'
    94. }
    95. ]
    96. ],
    97. });
    98. //- With callbacks on click
    99. var ac5 = app.actions.create({
    100. buttons: [
    101. {
    102. text: 'Button1',
    103. onClick: function () {
    104. }
    105. {
    106. text: 'Button2',
    107. onClick: function () {
    108. app.dialog.alert('Button2 clicked')
    109. }
    110. },
    111. {
    112. text: 'Cancel',
    113. color: 'red',
    114. onClick: function () {
    115. app.dialog.alert('Cancel clicked')
    116. }
    117. },
    118. ]
    119. });
    120. //- Actions Grid
    121. var ac6 = app.actions.create({
    122. grid: true,
    123. buttons: [
    124. [
    125. {
    126. text: 'Button 1',
    127. icon: '<img src="http://lorempixel.com/96/96/people/1" width="48"/>'
    128. },
    129. {
    130. text: 'Button 2',
    131. icon: '<img src="http://lorempixel.com/96/96/people/2" width="48">'
    132. },
    133. {
    134. text: 'Button 3',
    135. icon: '<img src="http://lorempixel.com/96/96/people/3" width="48">'
    136. },
    137. ],
    138. [
    139. {
    140. text: 'Button 1',
    141. icon: '<img src="http://lorempixel.com/96/96/fashion/4" width="48"/>'
    142. },
    143. {
    144. text: 'Button 2',
    145. icon: '<img src="http://lorempixel.com/96/96/fashion/5" width="48">'
    146. },
    147. {
    148. text: 'Button 3',
    149. icon: '<img src="http://lorempixel.com/96/96/fashion/6" width="48">'
    150. },
    151. ]
    152. ]
    153. });
    154. $$('.ac-1').on('click', function () {
    155. ac1.open();
    156. });
    157. $$('.ac-2').on('click', function () {
    158. ac2.open();
    159. });
    160. $$('.ac-3').on('click', function () {
    161. ac3.open();
    162. });
    163. $$('.ac-4').on('click', function () {
    164. ac4.open();
    165. });
    166. $$('.ac-5').on('click', function () {
    167. ac5.open();
    168. });
    169. $$('.ac-6').on('click', function () {
    170. });