Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tile): add custom event to selected-tile #9898

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @license
*
* Copyright IBM Corp. 2019, 2022
* Copyright IBM Corp. 2019, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
Expand Down Expand Up @@ -29,6 +29,7 @@ const { prefix } = settings;
* Multi-selectable tile.
*
* @element bx-selectable-tile
* @fires bx-selectable-tile-changed - The custom event fired after this selectable tile changes its selected state.
*/
@customElement(`${prefix}-selectable-tile`)
class BXSelectableTile extends FocusMixin(LitElement) {
Expand All @@ -45,6 +46,18 @@ class BXSelectableTile extends FocusMixin(LitElement) {
*/
protected _handleChange() {
this.selected = this._inputNode.checked;

const selected = this.selected;
const { eventChange } = this.constructor as typeof BXSelectableTile;
this.dispatchEvent(
new CustomEvent(eventChange, {
bubbles: true,
composed: true,
detail: {
selected,
},
})
);
}

/**
Expand Down Expand Up @@ -124,6 +137,13 @@ class BXSelectableTile extends FocusMixin(LitElement) {
`;
}

/**
* The name of the custom event fired after this selectable tile changes its selected state.
*/
static get eventChange() {
return `${prefix}-selectable-tile-changed`;
}

static styles = styles;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g.
</bx-selectable-tile>
```

## `<bx-selectable-tile>` attributes and properties
## `<bx-selectable-tile>` attributes and properties and events

Note: For `boolean` attributes, `true` means simply setting the attribute (e.g.
`<bx-selectable-tile selected>`) and `false` means not setting the attribute
Expand Down