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-segmentedbutton): initial implementation #1164

Merged
merged 14 commits into from
Feb 10, 2020

Conversation

ivoplashkov
Copy link
Member

@ivoplashkov ivoplashkov commented Jan 29, 2020

Initial implementation of the ui5-segmentedbutton component.
Fixes: #1180

this.widths = this.buttons.map(button => button.offsetWidth);
}

syncSelection() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not really synchronization. It's deselecting, if there are many selected. Think of a better name.

* @param {HTMLElement} pressedButton the pressed button.
* @public
*/
pressChange: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this name agreed upon? Press change sounds ok for the toggle button, but for segmented button it's more like "selectionChange". How is it in OpenUI5?

return this.toggle(event);
}

toggle(event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function seems to be only called from onclick. Just move the code there

}

toggle(event) {
if (event.target !== this.pressedButton) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is confusing a bit. It's the same as ._pressedButton. Do we need "pressedButton"? Is this the public API? Even if so, just check for ._pressedButton here

this.buttons.forEach(button => {
button.pressed = false;
});
this._pressedButton.pressed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this line do? If we set pressed to false to all buttons in the loop, isn't this unnecessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

We need this in order to leave the last pressed button, after we deselect all buttons.

pressedButton: this._pressedButton,
});
}
event.target.pressed = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better use ._pressedButton here.

class="ui5-segmentedbutton-root"
>
{{#each buttons}}
<slot name="{{this._individualSlot}}"></slot>
Copy link
Member

Choose a reason for hiding this comment

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

I am wondering if we need the individual slot assignment as we do not wrap the buttons in spans or anything else?

<div
	@click="{{_onclick}}"
	class="ui5-segmentedbutton-root"
>
    <slot></slot>
</div>

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

}

_handleResize() {
const documentWidth = document.body.clientWidth;
Copy link
Member

Choose a reason for hiding this comment

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

I found one issue:

  • First, open the test page in large size
  • Then, shrink the page to the point the component gets width: 100%;
  • Then, expand the page back - the segmented button remains with width: 100%,
    but should not.

*
* The <code>SegmentedButton</code> shows a group of buttons. When the user clicks or taps
* one of the buttons, it stays in a pressed state. It automatically resizes the buttons
* to fit proportionally within the control. When no width is set, the control uses the available width.
Copy link
Member

Choose a reason for hiding this comment

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

use "component", instead of "control"

packages/main/src/SegmentedButton.js Show resolved Hide resolved
packages/main/test/pages/SegmentedButton.html Show resolved Hide resolved
packages/main/src/SegmentedButton.js Show resolved Hide resolved
@ilhan007 ilhan007 dismissed stale reviews from vladitasev and themself February 10, 2020 12:41

outdated

@ilhan007 ilhan007 merged commit 931fbe0 into SAP:master Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SegmentedButton component
3 participants