Skip to content

Commit e0c7979

Browse files
xakaajoslin
authored andcommitted
feat ($ionicActionSheet): pass button object to buttonClicked
Closes #1369. Right now `buttonClicked` accepts only the index of the pressed button that means you have to work with indices to decide which one it is. In case you move buttons around to get better UX, you'd have to be very careful with those indices. It's easier to add `id` property to buttons and simply check for it. Index-agnostic solution is more maintainable and leads to less changes to the code when the buttons order is being changed.
1 parent 0c960b5 commit e0c7979

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

js/angular/service/actionSheet.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
6969
* - `{string=}` `destructiveText` The text for a 'danger' on the action sheet.
7070
* - `{function=}` `cancel` Called if the cancel button is pressed or the backdrop is tapped.
7171
* - `{function=}` `buttonClicked` Called when one of the non-destructive buttons is clicked,
72-
* with the index of the button that was clicked. Return true to close the action sheet,
73-
* or false to keep it opened.
72+
* with the index of the button that was clicked and the button object. Return true to close
73+
* the action sheet, or false to keep it opened.
7474
* - `{function=}` `destructiveButtonClicked` Called when the destructive button is clicked.
7575
* Return true to close the action sheet, or false to keep it opened.
7676
*/
@@ -80,7 +80,8 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
8080
extend(scope, {
8181
cancel: angular.noop,
8282
buttonClicked: angular.noop,
83-
destructiveButtonClicked: angular.noop
83+
destructiveButtonClicked: angular.noop,
84+
buttons: []
8485
}, opts);
8586

8687
// Compile the template
@@ -121,7 +122,7 @@ function($rootScope, $document, $compile, $animate, $timeout, $ionicTemplateLoad
121122
scope.buttonClicked = function(index) {
122123
// Check if the button click event returned true, which means
123124
// we can close the action sheet
124-
if((opts.buttonClicked && opts.buttonClicked(index)) === true) {
125+
if((opts.buttonClicked && opts.buttonClicked(index, opts.buttons[index])) === true) {
125126
hideSheet(false);
126127
}
127128
};

0 commit comments

Comments
 (0)