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(ui5-li): introduce deleteButton slot #5971

Merged
merged 2 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions packages/main/src/ListItem.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@

{{#if renderDeleteButton}}
<div class="ui5-li-deletebtn">
{{#if hasDeleteButtonSlot}}
<slot name="deleteButton"></slot>
{{else}}
<ui5-button
tabindex="-1"
data-sap-no-tab-ref
Expand All @@ -97,6 +100,7 @@
@click="{{onDelete}}"
tooltip="{{deleteText}}"
></ui5-button>
{{/if}}
</div>
{{/if}}

Expand Down
21 changes: 21 additions & 0 deletions packages/main/src/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ const metadata = {
_focused: {},
"_selection-requested": {},
},
managedSlots: true,
slots: /** @lends sap.ui.webcomponents.main.ListItem.prototype */ {

/**
* Defines the delete button, displayed in "Delete" mode.
* <b>Note:</b> While the slot allows custom buttons, to match
* design guidelines, please use the <code>ui5-button</code> component.
* <b>Note:</b> When the slot is not present, a built-in delete button will be displayed.
* @type {sap.ui.webcomponents.main.IButton}
* @since 1.9.0
* @slot
* @public
*/
deleteButton: {
type: HTMLElement,
},
},
};

/**
Expand Down Expand Up @@ -377,6 +394,10 @@ class ListItem extends ListItemBase {
return ListItem.i18nBundle.getText(DELETE);
}

get hasDeleteButtonSlot() {
return !!this.deleteButton.length;
}

get _accessibleNameRef() {
if (this.accessibleName) {
// accessibleName is set - return labels excluding content
Expand Down
5 changes: 5 additions & 0 deletions packages/main/test/pages/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ <h3 id="infoLbl">Items 3/3</h3>
<ui5-li id="bg">Bulgaria</ui5-li>
<ui5-li id="ch">China</ui5-li>
<ui5-li type="Detail">Detail item</ui5-li>
<ui5-li>Denmark
<div slot="deleteButton">
<ui5-button>Custom Delete Button</ui5-button>
</div>
</ui5-li>
</ui5-list>

<br/><br/>
Expand Down
10 changes: 10 additions & 0 deletions packages/main/test/samples/List.sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,23 @@ <h3>List in Delete Mode</h3>
<ui5-li>Argentina</ui5-li>
<ui5-li>Bulgaria</ui5-li>
<ui5-li>China</ui5-li>
<ui5-li>Denmark
<div slot="deleteButton">
<ui5-button>Custom Delete Button</ui5-button>
</div>
</ui5-li>
</ui5-list>
</div>
<pre class="prettyprint lang-html"><xmp>
<ui5-list id="myList5" mode="Delete" header-text="Note: The list items removal is up to application developers">
<ui5-li>Argentina</ui5-li>
<ui5-li>Bulgaria</ui5-li>
<ui5-li>China</ui5-li>
<ui5-li>Denmark
<div slot="deleteButton">
<ui5-button>Custom Delete Button</ui5-button>
</div>
</ui5-li>
</ui5-list>
</xmp></pre>
</section>
Expand Down