Repository navigation
fix(menu): change side when rtl - #11190
jlucfarias wants to merge 6 commits into
Conversation
for menus *Note:* the menu will be in the better side of the html direction only when the page load the first time.
|
@AmitMY I will think later about your use case |
|
|
||
| // normalize the "side" | ||
| if (this.side !== 'left' && this.side !== 'right') { | ||
| if (this.side !== 'left' && this.side !== 'right' && !_plt.isRTL()) { |
There was a problem hiding this comment.
Instead, what do you think about doing:
if (this.side !== 'left' && this.side !== 'right') {
this.side = _plt.isRTL()? 'right': 'left';
}
It is cleaner imo.
| else if (this.side !== 'left' && this.side !== 'right' && _plt.isRTL()) { | ||
| this.side = 'right'; | ||
| } | ||
| this.setElementAttribute('side', this.side); |
There was a problem hiding this comment.
only when side is not previously set
|
If you already are changing the menu sides, how about this behaviour:
Also, |
|
I like that idea @AmitMY. I think we should keep |
|
Can you review the new changes? @AmitMY @brandyscarney |
| if (this.menu.side === 'right' || (this.menu.side === 'start' && this.plt.isRTL()) || (this.menu.side === 'end' && !this.plt.isRTL())) { | ||
| let z = slide.min; | ||
| } | ||
|
|
There was a problem hiding this comment.
2 unnecessary break lines, it should be } else {.
Also, use else instead of else if as this is the exact opposite, and there is no default set.
This applies to lines: 62-64, 107-108
and on menu-types file as well: 89-91, 119-121, 153-154,
and on menu file: 344-345
|
This looks pretty good. covering a lot of ground with the menu, well done. Input: ['left', 'right', 'start', 'end'], Output: ['left', 'right'] This will basically standardise the Some work is missing for the |
| else if (this.side !== 'left' && this.side !== 'right' && this.side !== 'start' && this.side !== 'end' && _plt.isRTL()) { | ||
| this.side = 'right'; | ||
| } | ||
| this.setElementAttribute('side', this.side); |
There was a problem hiding this comment.
This line will break the change. Let's say I have 'start', after construct is done, it will be left.
this.side should remain with the same value, then, wherever there is usage of this.side in the menu, it should be only left and right. Take a look at the function I wrote, to make it nicer.
- Note - this part of the code should not even exist (342-347). It should say:
if (['left', 'right', 'start', 'end'].indexOf(this.side) === -1) {
this.side = 'start'; // default
this.setElementAttribute('side', this.side);
}
instead of `else if` use the `else` condition
|
Do you think that I need change the |
|
That looks like a great idea. Set saves the ideal side - left/right/start/end |
|
like this? if it's ok what about this part? what I need to do here? |
|
Well, opposite. Something like: Note that I set default value to be |
|
where are I put that |
|
Above the menu class, it will work. (Under imports) |
|
ngOnInit should have any change? |
|
Hmm.. I think should remove lines 342-346, and only keep the I think you should add a test to: (and of course, As an overview, without running anything, this looks good for now in my opinion. @brandyscarney Any additional feedback? this is the most important rtl "bug" currently, in my perspective. (Note, #11233 is completing it with the slide and the effect) |
| private _gestureBlocker: BlockerDelegate; | ||
| private _isPane: boolean = false; | ||
| private _side: side = 'start'; | ||
| private _plt: Platform; |
There was a problem hiding this comment.
_plt is already injected in the constructor.
| */ | ||
| @Input() side: string; | ||
| get side(): side { | ||
| if (val === 'right' || (val === 'start' && _plt.isRTL()) || (val === 'end' && !_plt.isRTL())) { |
There was a problem hiding this comment.
this._plt rather than _plt which is undefined
| expect(menu).toEqual(someMenu); | ||
| }); | ||
|
|
||
| it('should get the only right menu when is rtl', () => { |
There was a problem hiding this comment.
I am not sure how, but for this, and the end=left you need to inject Platform, and set direction to rtl
If you would run these tests, they won't pass
There was a problem hiding this comment.
I add the platform in mockMenu but I don't now how to access it. I think this
let someMenu = mockMenu();
someMenu._plt.setDir('rtl', true);
but I don't know if it's right
There was a problem hiding this comment.
the platform is set to private, so no.
@brandyscarney or @jgw96, can you help on this point?
There was a problem hiding this comment.
perhaps if we change the platform from private to protected they will be accessed from the mockMenu
There was a problem hiding this comment.
@John-Luke that will indeed work, no doubt, but they have set it to private, and I guess they are knowing what they are doing better than us :)
There was a problem hiding this comment.
I think that they set it to private because didn't have the necessity to use in deriving classes
| min: -this.menu.width(), | ||
| max: 0 | ||
| }; | ||
| } else { |
There was a problem hiding this comment.
let's only include the relevant changes in this PR. why did you refactor the "otherwise" condition?
| menuClosedX = menu.width() + 'px'; | ||
| menuOpenedX = '0px'; | ||
|
|
||
| menuClosedX = menu.width() + 'px'; |
manucorporat
left a comment
There was a problem hiding this comment.
this.menu.side === 'right' || (this.menu.side === 'start' && this.plt.isRTL()) || (this.menu.side === 'end' && !this.plt.isRTL())
this condition is repeated a lot across the code, we should add another auxiliar private function in menu.ts instead, for example, one that returns a boolean:
_isRightSide(): boolean {
switch (this.side) {
case 'right': return true;
case 'left': return false;
case 'end': return !this._plt.isRTL();
// 'start' by default
default: return this._plt.isRTL();
}
}
where 'start' is the default value.
Have you tested your changes?
| /** | ||
| * @input {string} Which side of the view the menu should be placed. Default `"left"`. | ||
| */ | ||
| @Input() side: string; |
There was a problem hiding this comment.
I don't see the point of this change
| private _events: UIEventManager; | ||
| private _gestureBlocker: BlockerDelegate; | ||
| private _isPane: boolean = false; | ||
| private _side: side = 'start'; |
There was a problem hiding this comment.
we don't need a new '_side' variable either
There was a problem hiding this comment.
The idea behind having _side and @Input() side is that the _side has 4 possible values: ['left', 'right', 'start', 'end']
While the private magic variable side has only two values: ['left', 'right']
This makes it easier for the rest of that file. Every time there is a reference to side, it will evaluate _side and return the correct one for that specific call. start can return left or right, depending on platform, etc..
There was a problem hiding this comment.
@AmitMY then why is:
if (this._side === 'right' || (this._side === 'start' && this._plt.isRTL()) || (this._side === 'end' && !this._plt.isRTL())) {
repeated across menu-gesture?
There was a problem hiding this comment.
@manucorporat I can only guess that this PR derailed a bit, and went through many changes that some stuff got left behind..
I thing I will fork this, and create a new cleaner PR.
Can you please comment on the tests? How can you access Platform / how can you run specific tests on different directions?
| onSlide(slide: SlideData, ev: any) { | ||
| let z = (this.menu.side === 'right' ? slide.min : slide.max); | ||
| if (this.menu.side === 'right' || (this.menu.side === 'start' && this.plt.isRTL()) || (this.menu.side === 'end' && !this.plt.isRTL())) { | ||
| let z = slide.min; |
There was a problem hiding this comment.
the scope of z should be the root of the function
|
@manucorporat |
|
@manucorporat This can be closed as well, as previous merged PR was based on it |
Note: the menu will be in the better side of the html direction when the page load the first time.
Short description of what this resolves:
Change for the better side when direction is rtl
Ionic Version: 1.x / 2.x / 3.x
Fixes partially: #11115