-
Notifications
You must be signed in to change notification settings - Fork 89
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
dropdown: get rid of wrapping root div
node (close #1392)
#1393
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
18 changes: 11 additions & 7 deletions
18
common.blocks/dropdown/_switcher/dropdown_switcher_button.bemhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
block('dropdown').mod('switcher', 'button').elem('switcher').content()(function() { | ||
var content = this.ctx.content; | ||
if(Array.isArray(content)) return content; | ||
block('dropdown').mod('switcher', 'button').elem('switcher').def()(function() { | ||
var dropdown = this._dropdown, | ||
switcher = dropdown.switcher; | ||
|
||
var res = this.isSimple(content)? | ||
{ block : 'button', text : content } : | ||
content; | ||
if(Array.isArray(switcher)) return switcher; | ||
|
||
var res = this.isSimple(switcher)? | ||
{ block : 'button', text : switcher } : | ||
switcher; | ||
|
||
if(res.block === 'button') { | ||
var resMods = res.mods || (res.mods = {}), | ||
dropdownMods = this.mods; | ||
resMods.size || (resMods.size = dropdownMods.size); | ||
resMods.theme || (resMods.theme = dropdownMods.theme); | ||
resMods.disabled = dropdownMods.disabled; | ||
|
||
res.mix = apply('mix'); | ||
} | ||
|
||
return res; | ||
return applyCtx(res); | ||
}); |
14 changes: 9 additions & 5 deletions
14
common.blocks/dropdown/_switcher/dropdown_switcher_button.bh.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 11 additions & 7 deletions
18
common.blocks/dropdown/_switcher/dropdown_switcher_link.bemhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
block('dropdown').mod('switcher', 'link').elem('switcher').content()(function() { | ||
var content = this.ctx.content; | ||
if(Array.isArray(content)) return content; | ||
block('dropdown').mod('switcher', 'link').elem('switcher').def()(function() { | ||
var dropdown = this._dropdown, | ||
switcher = dropdown.switcher; | ||
|
||
var res = this.isSimple(content)? | ||
{ block : 'link', mods : { pseudo : true }, content : content } : | ||
content; | ||
if(Array.isArray(switcher)) return switcher; | ||
|
||
var res = this.isSimple(switcher)? | ||
{ block : 'link', mods : { pseudo : true }, content : switcher } : | ||
switcher; | ||
|
||
if(res.block === 'link') { | ||
var resMods = res.mods || (res.mods = {}), | ||
dropdownMods = this.mods; | ||
resMods.theme || (resMods.theme = dropdownMods.theme); | ||
resMods.disabled = dropdownMods.disabled; | ||
|
||
res.mix = apply('mix'); | ||
} | ||
|
||
return res; | ||
return applyCtx(res); | ||
}); |
14 changes: 9 additions & 5 deletions
14
common.blocks/dropdown/_switcher/dropdown_switcher_link.bh.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,47 @@ | ||
module.exports = function(bh) { | ||
|
||
bh.match('dropdown', function(ctx, json) { | ||
ctx.js(true); | ||
bh.match({ | ||
'dropdown' : function(ctx) { | ||
var dropdown = ctx.json(); | ||
|
||
var popup = json.popup; | ||
ctx | ||
.js(ctx.extend({ id : ctx.generateId() }, ctx.js())) | ||
.tParam('dropdown', dropdown) | ||
.tParam('theme', ctx.mod('theme')) | ||
.tParam('mix', [dropdown].concat( | ||
dropdown.switcher.mix || [], | ||
dropdown.mix || [])); | ||
|
||
if(ctx.isSimple(popup) || popup.block !== 'popup') { | ||
popup = { block : 'popup', content : popup }; | ||
} | ||
return [{ elem : 'switcher' }, { elem : 'popup' }]; | ||
}, | ||
|
||
'dropdown__popup' : function(ctx) { | ||
var dropdown = ctx.tParam('dropdown'), | ||
popup = dropdown.popup; | ||
|
||
if(ctx.isSimple(popup) || popup.block !== 'popup') { | ||
popup = { block : 'popup', content : popup }; | ||
} | ||
|
||
var popupMods = popup.mods || (popup.mods = {}); | ||
popupMods.theme || (popupMods.theme = ctx.tParam('theme')); | ||
popupMods.hasOwnProperty('autoclosable') || (popupMods.autoclosable = true); | ||
|
||
var popupMods = popup.mods || (popup.mods = {}); | ||
popupMods.theme || (popupMods.theme = ctx.mod('theme')); | ||
popupMods.hasOwnProperty('autoclosable') || (popupMods.autoclosable = true); | ||
popupMods.target = 'anchor'; | ||
|
||
popupMods.target = 'anchor'; | ||
popup.mix = [dropdown].concat(popup.mix || []); | ||
|
||
ctx.content([ | ||
{ elem : 'switcher', content : json.switcher }, | ||
popup | ||
], true); | ||
return popup; | ||
}, | ||
|
||
'dropdown__switcher' : function(ctx) { | ||
var dropdown = ctx.tParam('dropdown'), | ||
switcher = dropdown.switcher; | ||
|
||
switcher.block && (switcher.mix = ctx.tParam('mix')); | ||
|
||
return switcher; | ||
} | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
common.blocks/dropdown/dropdown.tmpl-specs/10-default_link.bemjson.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
common.blocks/dropdown/dropdown.tmpl-specs/10-default_link.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<div class="dropdown dropdown_switcher_link dropdown_theme_islands dropdown_disabled i-bem" data-bem="{"dropdown":{}}"><span class="link link_pseudo link_theme_islands link_disabled link__control i-bem" data-bem="{"link":{}}">link</span><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor i-bem" data-bem="{"popup":{}}">bemjson</div></div> | ||
<span class="link link_pseudo link_theme_islands link_disabled link__control dropdown dropdown_switcher_link dropdown_theme_islands dropdown_disabled i-bem" data-bem="{"link":{},"dropdown":{"id":"uniq14257605137441"}}">link</span><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor dropdown dropdown_switcher_link dropdown_theme_islands dropdown_disabled i-bem" data-bem="{"popup":{},"dropdown":{"id":"uniq14257605137441"}}">bemjson</div> |
1 change: 1 addition & 0 deletions
1
common.blocks/dropdown/dropdown.tmpl-specs/20-default_button.bemjson.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
common.blocks/dropdown/dropdown.tmpl-specs/20-default_button.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<div class="dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m dropdown_disabled i-bem" data-bem="{"dropdown":{}}"><button class="button button_size_m button_theme_islands button_disabled button__control i-bem" data-bem="{"button":{}}" role="button" type="button" disabled="disabled"><span class="button__text">button</span></button><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor i-bem" data-bem="{"popup":{}}">bemjson</div></div> | ||
<button class="button button_size_m button_theme_islands button_disabled button__control dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m dropdown_disabled i-bem" data-bem="{"button":{},"dropdown":{"id":"uniq14257605137441"}}" role="button" type="button" disabled="disabled"><span class="button__text">button</span></button><div class="popup popup_theme_islands popup_autoclosable popup_target_anchor dropdown dropdown_switcher_button dropdown_theme_islands dropdown_size_m dropdown_disabled i-bem" data-bem="{"popup":{},"dropdown":{"id":"uniq14257605137441"}}">bemjson</div> |
1 change: 1 addition & 0 deletions
1
common.blocks/dropdown/dropdown.tmpl-specs/30-switcher_link_custom_popup.bemjson.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
common.blocks/dropdown/dropdown.tmpl-specs/30-switcher_link_custom_popup.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<div class="dropdown dropdown_switcher_link i-bem" data-bem="{"dropdown":{}}"><a class="link link_theme_islands link__control i-bem" data-bem="{"link":{}}" tabindex="0">link</a><div class="popup popup_autoclosable popup_target_anchor i-bem" data-bem="{"popup":{}}"><a class="link link_theme_islands link__control i-bem" data-bem="{"link":{}}" tabindex="0">link</a></div></div> | ||
<a class="link link_theme_islands dropdown dropdown_switcher_link link__control i-bem" tabindex="0" data-bem="{"link":{},"dropdown":{"id":"uniq14257605137441"}}">link</a><div class="popup popup_autoclosable popup_target_anchor dropdown dropdown_switcher_link i-bem" data-bem="{"popup":{},"dropdown":{"id":"uniq14257605137441"}}"><a class="link link_theme_islands link__control i-bem" tabindex="0" data-bem="{"link":{}}">link</a></div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think about moving
onSwitcherClick
to prototype.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is not that obvious. As far as I remember it was made this way not but the mistake. One must check how clear this API will be from the pov of block inheritance. E.g. what will happen if someone will redefine
onSwitcherClick
within modifier without calling base?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @dfilatov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to think about it separately from this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @dfilatov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered to do #1502 in
v3
.