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-switch): provide tooltip property #5954

Merged
merged 1 commit into from
Oct 28, 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
1 change: 1 addition & 0 deletions packages/main/src/Switch.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@keydown="{{_onkeydown}}"
tabindex="{{tabIndex}}"
dir="{{effectiveDir}}"
title="{{tooltip}}"
>
<div class="ui5-switch-inner">
<div class="ui5-switch-track" part="slider">
Expand Down
13 changes: 13 additions & 0 deletions packages/main/src/Switch.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ const metadata = {
type: String,
defaultValue: "",
},

/**
* Defines the tooltip of the component.
* <br>
* <b>Note:</b> If applicable an external label reference should always be the preferred option to provide context to the <code>ui5-switch</code> component over a tooltip.
* @type {string}
* @defaultvalue: ""
* @public
* @since 1.9.0
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case we need to provide API for setting the tooltip, we often provide a private property, called "title".
And because it's called "title" we operate with the value of the standard HTML "title" attribute. This is done in several components already: see Option, TreeItem, ListItem, SideNavigationItem

/**
* Defines the tooltip of the component.
* @type {string}
* @DefaultValue ""
* @Private
*/
title: {
type: String,
},

There is a "tooltip" in Button, can't recall the reason, but at least initially you can support the native way of setting a tooltip - with the "title" via the private "title" property. In case there is some specific things that requires a separate property, you can always do that.

<ui5-switch title="my cool tooltip"></ui5-switch>

Advantages

  • native way for setting tooltip
  • no public API
  • tooltip property can be always added later if required

Copy link
Member

@ilhan007 ilhan007 Oct 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, there might be duplicate reading with Jaws... so yes it may not work for you (you can test it if not already). If that's the case "tooltip" is fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked it with JAWS and it's read out twice if we use title. I think we have to stick to the tooltip solution

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I approve +1

tooltip: {
type: String,
},
},
events: /** @lends sap.ui.webcomponents.main.Switch.prototype */ {

Expand Down
1 change: 1 addition & 0 deletions packages/main/test/pages/Switch.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ <h3>Default Switch</h3>
</div>

<div class="switch2auto">
<ui5-switch id="switchTooltip" tooltip="Use GPS location" class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
<ui5-switch id="switchAccName" accessible-name="Geographical location" class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
<ui5-label id="descriptionText">Use GPS location</ui5-label>
<ui5-switch id="switchAccNameRef" accessible-name-ref="descriptionText" class="switch3auto" text-on="Yes" text-off="No"></ui5-switch>
Expand Down
10 changes: 8 additions & 2 deletions packages/main/test/specs/Switch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,26 @@ describe("Switch general interaction", async () => {
assert.strictEqual(await field.getProperty("value"), "3", "Change event should not be called any more");
});

it("setting accessible-name on the host is reflected on the button tag", async () => {
it("setting accessible-name on the host is reflected on the root element", async () => {
const switchEl = await browser.$("#switchAccName").shadow$("div");

assert.strictEqual(await switchEl.getAttribute("role"), "switch", "Proper role attribute is set");
assert.strictEqual(await switchEl.getAttribute("aria-label"), "Geographical location No", "Attribute is reflected");
});

it("setting accessible-name-ref on the host is reflected on the button tag", async () => {
it("setting accessible-name-ref on the host is reflected on the root element", async () => {
const switchEl = await browser.$("#switchAccNameRef").shadow$("div");

assert.strictEqual(await switchEl.getAttribute("role"), "switch", "Proper role attribute is set");
assert.strictEqual(await switchEl.getAttribute("aria-label"), "Use GPS location No", "Attribute is reflected");
});

it("setting tooltip on the host is reflected on the root element", async () => {
const switchEl = await browser.$("#switchTooltip").shadow$("div");

assert.strictEqual(await switchEl.getAttribute("title"), "Use GPS location", "Attribute is reflected");
});

it("aria-label attribute is properly set when text-on and text-off attributes aren't set", async () => {
const switchEl = await browser.$("#noLabel").shadow$("div");

Expand Down