保持Dash中下拉菜单的虚拟尺寸不变 – Python

huangapple go评论100阅读模式
英文:

Keeping the virtual size of drop down menus unchanged in Dash - Python

问题

我有多个下拉菜单,其中有数十个选项可供选择。随着用户选择越来越多的选项,下拉菜单的大小会变大。有没有办法保持大小不变,并以更短的方式显示选择项?我在样式选项中设置了最大宽度参数,但它没有按预期工作。

英文:

I have multiple drop down menus having tens of options to select. As the user selects more and more options, the size of the drop down menu gets larger. Is there a way to keep the size unchanged and show the selections in a shorter way? I set the max width parameters in the style option, but it does not work as intended.

  1. from dash import Dash, dcc, html
  2. external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
  3. app = Dash(__name__, external_stylesheets=external_stylesheets)
  4. app.layout = html.Div([
  5. html.Div(className="row", children=[
  6. html.Div(className='row', children=[
  7. html.Div(className='four columns', children=[
  8. dcc.Dropdown(
  9. options=[
  10. {'label': 'North America', 'value': 'NA'},
  11. {'label': 'Europe', 'value': 'EU'},
  12. {'label': 'Asia', 'value': 'AS'}
  13. ],
  14. multi=True
  15. )
  16. ]),
  17. html.Div(className='four columns', children=[
  18. dcc.Dropdown(
  19. options=[
  20. {'label': 'United States', 'value': 'USA'},
  21. {'label': 'Canada', 'value': 'CAN'},
  22. {'label': 'France', 'value': 'FRA'},
  23. {'label': 'Germany', 'value': 'GER'},
  24. {'label': 'China', 'value': 'CHN'},
  25. {'label': 'India', 'value': 'IND'}
  26. ],
  27. multi=True
  28. )
  29. ]),
  30. html.Div(className='four columns', children=[
  31. dcc.Dropdown(
  32. options=[
  33. {'label': 'New York City', 'value': 'NYC'},
  34. {'label': 'Montreal', 'value': 'MTL'},
  35. {'label': 'San Francisco', 'value': 'SF'},
  36. {'label': 'London', 'value': 'LDN'},
  37. {'label': 'Tokyo', 'value': 'TKY'},
  38. {'label': 'Mumbai', 'value': 'MUM'}
  39. ],
  40. multi=True
  41. )
  42. ])
  43. ]),
  44. ])
  45. ])
  46. if __name__ == '__main__':
  47. app.run(debug=True)

保持Dash中下拉菜单的虚拟尺寸不变 – Python

答案1

得分: 0

我遇到了相同的样式问题,并创建了这个自定义CSS,重新设计了多选组件,具体如下:选定的值不会换行,您可以水平滚动以查看它们全部,始终保持相同的高度和宽度。

这是一种个人口味的问题,但可能会有用,所以我在这里发布它:

  1. .Select--multi > .Select-control {
  2. display: flex;
  3. align-items: center;
  4. }
  5. .Select--multi .Select-multi-value-wrapper {
  6. flex: 1;
  7. white-space: nowrap;
  8. overflow-x: scroll;
  9. overflow-y: hidden;
  10. box-shadow: inset -7px 0 9px -7px rgb(187 187 187);
  11. }
  12. .Select-multi-value-wrapper::-webkit-scrollbar {
  13. display: none;
  14. }
英文:

I had the same styling issue and came up with this custom CSS that restyles the multi-selection component as follow: the selected values don't wrap and you can horizontally scroll to see them all, keeping the same height and width at all time.

It's a matter of taste but can be useful, so I post it here:

  1. .Select--multi > .Select-control {
  2. display: flex;
  3. align-items: center;
  4. }
  5. .Select--multi .Select-multi-value-wrapper {
  6. flex: 1;
  7. white-space: nowrap;
  8. overflow-x: scroll;
  9. overflow-y: hidden;
  10. box-shadow: inset -7px 0 9px -7px rgb(187 187 187);
  11. }
  12. .Select-multi-value-wrapper::-webkit-scrollbar {
  13. display: none;
  14. }

huangapple
  • 本文由 发表于 2023年7月12日 21:58:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定