Skip to content

Fixed viewport meta-tags #2084

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

Merged
merged 3 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## Unreleased

### Fixed
- [#2084](https://github.com/plotly/dash/pull/2084) In dash 2.5.0, a default viewport meta tag was added as recommended for mobile-optimized sites by [mdn](https://developer.mozilla.org/en-US/docs/Web/HTML/Viewport_meta_tag)
This feature can be disabled by providing an empty viewport meta tag. e.g. `app = Dash(meta_tags=[{"name": "viewport"}])`

## [2.5.0] - 2022-06-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion dash/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def _generate_meta_html(self):
x.get("http-equiv", "") == "X-UA-Compatible" for x in meta_tags
)
has_charset = any("charset" in x for x in meta_tags)
has_viewport = any("viewport" in x for x in meta_tags)
has_viewport = any(x.get("name") == "viewport" for x in meta_tags)

tags = []
if not has_ie_compat:
Expand Down
27 changes: 23 additions & 4 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from dash.testing.wait import until


def test_inin004_wildcard_data_attributes(dash_duo):
def test_inin003_wildcard_data_attributes(dash_duo):
app = Dash()
test_time = datetime.datetime(2012, 1, 10, 2, 3)
test_date = datetime.date(test_time.year, test_time.month, test_time.day)
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_inin004_wildcard_data_attributes(dash_duo):
assert dash_duo.get_logs() == []


def test_inin005_no_props_component(dash_duo):
def test_inin004_no_props_component(dash_duo):
app = Dash()
app.layout = html.Div(
[
Expand All @@ -71,7 +71,7 @@ def test_inin005_no_props_component(dash_duo):
assert re.sub("\\s+", " ", inner) == expected


def test_inin006_flow_component(dash_duo):
def test_inin005_flow_component(dash_duo):
app = Dash()

app.layout = html.Div(
Expand Down Expand Up @@ -109,7 +109,7 @@ def display_output(react_value, flow_value):
dash_duo.percy_snapshot(name="flowtype")


def test_inin007_meta_tags(dash_duo):
def test_inin006_meta_tags(dash_duo):
metas = [
{"name": "description", "content": "my dash app"},
{"name": "custom", "content": "customized"},
Expand All @@ -133,6 +133,25 @@ def test_inin007_meta_tags(dash_duo):
assert meta_tag.get_attribute("content") == meta_info["content"]


def test_inin007_change_viewport_meta_tag(dash_duo):
"""
As of dash 2.5 the default viewport meta tag is:
[{"name": "viewport", "content": "width=device-width, initial-scale=1"}]
Test verifies that this feature can be disabled by using an empty viewport tag.
"""

app = Dash(meta_tags=[{"name": "viewport"}])

app.layout = html.Div(id="content")

dash_duo.start_server(app)

viewport_meta = dash_duo.find_elements('meta[name="viewport"]')

assert len(viewport_meta) == 1, "Should have 1 viewport meta tags"
assert viewport_meta[0].get_attribute("content") == ""


def test_inin008_index_customization(dash_duo):
app = Dash()

Expand Down