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

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

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.

from dash import Dash, dcc, html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div([
    html.Div(className="row", children=[
            html.Div(className='row', children=[
                html.Div(className='four columns', children=[

                    dcc.Dropdown(
                        options=[
                            {'label': 'North America', 'value': 'NA'},
                            {'label': 'Europe', 'value': 'EU'},
                            {'label': 'Asia', 'value': 'AS'}
                        ],
                        multi=True
                    )
                ]),
                html.Div(className='four columns', children=[
                    dcc.Dropdown(
                        options=[
                            {'label': 'United States', 'value': 'USA'},
                            {'label': 'Canada', 'value': 'CAN'},
                            {'label': 'France', 'value': 'FRA'},
                            {'label': 'Germany', 'value': 'GER'},
                            {'label': 'China', 'value': 'CHN'},
                            {'label': 'India', 'value': 'IND'}
                        ],
                        multi=True
                    )
                ]),
                html.Div(className='four columns', children=[
                    dcc.Dropdown(
                        options=[
                            {'label': 'New York City', 'value': 'NYC'},
                            {'label': 'Montreal', 'value': 'MTL'},
                            {'label': 'San Francisco', 'value': 'SF'},
                            {'label': 'London', 'value': 'LDN'},
                            {'label': 'Tokyo', 'value': 'TKY'},
                            {'label': 'Mumbai', 'value': 'MUM'}
                        ],
                        multi=True
                    )
                ])

            ]),

    ])
])

if __name__ == '__main__':
    app.run(debug=True)

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

答案1

得分: 0

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

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

.Select--multi > .Select-control {
  display: flex;
  align-items: center;
}

.Select--multi .Select-multi-value-wrapper {
  flex: 1;
  white-space: nowrap;
  overflow-x: scroll;
  overflow-y: hidden;
  box-shadow: inset -7px 0 9px -7px rgb(187 187 187);
}

.Select-multi-value-wrapper::-webkit-scrollbar {
  display: none;
}
英文:

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:

.Select--multi > .Select-control {
  display: flex;
  align-items: center;
}

.Select--multi .Select-multi-value-wrapper {
  flex: 1;
  white-space: nowrap;
  overflow-x: scroll;
  overflow-y: hidden;
  box-shadow: inset -7px 0 9px -7px rgb(187 187 187);
}

.Select-multi-value-wrapper::-webkit-scrollbar {
  display: none;
}

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:

确定