Skip to content

Commit

Permalink
feat(tile): add custom event to selected-tile (carbon-design-system…
Browse files Browse the repository at this point in the history
…#9898)

### Related Ticket(s)

carbon-design-system#9740 

### Description

Adds custom event after `selectable-tile` is selected

### Changelog

**New**

- `bx-selectable-tile-changed` custom event added to `selectable-tile`

<!-- React and Web Component deploy previews are enabled by default. -->
<!-- To enable additional available deploy previews, apply the following -->
<!-- labels for the corresponding package: -->
<!-- *** "test: e2e": Codesandbox examples and e2e integration tests -->
<!-- *** "package: services": Services -->
<!-- *** "package: utilities": Utilities -->
<!-- *** "RTL": React / Web Components (RTL) -->
<!-- *** "feature flag": React / Web Components (experimental) -->
  • Loading branch information
kennylam authored Jan 17, 2023
1 parent 4759855 commit 16adc45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
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

0 comments on commit 16adc45

Please sign in to comment.