Skip to content

Commit cd1f17d

Browse files
fix(scroll): use scroll-to-input-offset value if available (#1185)
The previous functionality was returning zero if the `scroll-to-input-offset` attribute was missing, otherwise it was returning the default value (120). There was no path which returned the value of `scroll-to-input-offset` if available. - Created a new demo "Scroll to Input Offset" - Corrected the value return - Fixed a few typos in the demo and documentation | Before | After | | -- | -- | | ![before](https://github.com/user-attachments/assets/1bcf806c-4b20-4bcf-b95e-4d904dc78dac) | ![after](https://github.com/user-attachments/assets/a49278dc-138e-4da2-8b28-a150b7baa999) | [Asana](https://app.asana.com/1/47184964732898/project/1204008699308084/task/1210525849054931?focus=true)
1 parent ee04e36 commit cd1f17d

7 files changed

Lines changed: 122 additions & 5 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<style
2+
id="form-group"
3+
flex="1"
4+
marginLeft="24"
5+
marginRight="24"
6+
marginTop="24"
7+
/>
8+
<style
9+
id="input"
10+
borderBottomColor="#E1E1E1"
11+
borderBottomWidth="1"
12+
borderColor="#4E4D4D"
13+
flex="1"
14+
fontSize="16"
15+
fontWeight="normal"
16+
paddingBottom="8"
17+
paddingTop="8"
18+
>
19+
<modifier focused="true">
20+
<style borderBottomColor="#4778FF" />
21+
</modifier>
22+
</style>
23+
<style id="input-error" borderBottomColor="#FF4847" color="#FF4847">
24+
<modifier focused="true">
25+
<style borderBottomColor="#FF4847" />
26+
</modifier>
27+
</style>
28+
<style
29+
id="label"
30+
borderColor="#4E4D4D"
31+
fontSize="16"
32+
fontWeight="bold"
33+
lineHeight="24"
34+
marginBottom="8"
35+
/>
36+
<style
37+
id="help"
38+
borderColor="#FF4847"
39+
fontSize="16"
40+
fontWeight="normal"
41+
lineHeight="24"
42+
marginTop="16"
43+
/>
44+
<style id="help-error" color="#FF4847" />
45+
<style
46+
id="submit"
47+
color="#4778FF"
48+
fontSize="16"
49+
fontWeight="bold"
50+
lineHeight="24"
51+
marginLeft="24"
52+
marginTop="16"
53+
/>
54+
<style id="spacer" height="200" />
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
permalink: "/advanced/case-studies/scroll-to-input/index.xml"
3+
tags: "Advanced/Case Studies"
4+
hv_title: "Scroll to Input Offset"
5+
hv_button_behavior: "back"
6+
---
7+
{% extends 'templates/base.xml.njk' %}
8+
{% from 'macros/description/index.xml.njk' import description %}
9+
10+
{% block styles %}
11+
{% include './_styles.xml.njk' %}
12+
{% endblock %}
13+
14+
{% block container %}
15+
<form id="myScrollForm" scroll="true" scroll-to-input-offset="450">
16+
{{ description('Scroll to input offset is a property that can be used to scroll to an input field when it is focused.') }}
17+
<view style="spacer" />
18+
<view style="spacer" />
19+
<view style="form-group">
20+
<text style="label">Label line</text>
21+
<text-field
22+
name="data"
23+
placeholder="Placeholder"
24+
placeholderTextColor="#8D9494"
25+
style="input"
26+
/>
27+
</view>
28+
<text
29+
action="replace"
30+
href="/hyperview/public/advanced/case-studies/scroll-to-input/submit.xml"
31+
show-during-load="mySpinner"
32+
style="submit"
33+
target="myScrollForm"
34+
>
35+
Submit
36+
</text>
37+
<view style="spacer" />
38+
<view style="spacer" />
39+
<view style="spacer" />
40+
<view style="spacer" />
41+
{{ description('Bottom of the form') }}
42+
</form>
43+
<spinner id="mySpinner" hide="true" />
44+
{% endblock %}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<form
2+
id="myScrollForm"
3+
scroll="true"
4+
xmlns="https://hyperview.org/hyperview"
5+
scroll-to-input-offset="512"
6+
>
7+
<view style="form-group">
8+
<text style="label">Label line</text>
9+
<text-field
10+
name="data"
11+
placeholder="Placeholder"
12+
placeholderTextColor="#8D9494"
13+
style="input"
14+
value=""
15+
/>
16+
</view>
17+
<text style="submit">Saved!</text>
18+
</form>

demo/backend/ui/ui-elements/forms/text-field/index.xml.njk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ hv_button_behavior: "back"
2323
{% endblock %}
2424
2525
{% block content %}
26-
{{ about('Text field are used in forms to collect textual data') }}
26+
{{ about('Text fields are used in forms to collect textual data') }}
2727
{% include './_form.xml.njk' %}
2828
{% endblock %}

docs/reference_view.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ An attribute indicating the direction in which the view will scroll.
111111

112112
#### `scroll-to-input-offset`
113113

114-
| Type | Required |
115-
| ------ | ----------------------- |
116-
| number | No (defauls to **120**) |
114+
| Type | Required |
115+
| ------ | ------------------------ |
116+
| number | No (defaults to **120**) |
117117

118118
An attribute defining an additional scroll offset to be applied to the view, when a `<text-field>` is focused. Only valid in combination with attribute `scroll` set to `"true"`.
119119

schema/core.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@
456456
<xs:attribute name="safe-area" type="xs:boolean" />
457457
<xs:attribute name="value" type="xs:string" />
458458
<xs:attribute name="sticky" type="xs:boolean" />
459+
<xs:attribute name="scroll-to-input-offset" type="xs:nonNegativeInteger" />
459460
<xs:attributeGroup ref="hv:behaviorAttributes" />
460461
<xs:attributeGroup ref="hv:scrollAttributes" />
461462
</xs:attributeGroup>

src/components/hv-view/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default class HvView extends PureComponent<HvComponentProps> {
137137
const offsetStr = this.attributes[ATTRIBUTES.SCROLL_TO_INPUT_OFFSET];
138138
if (offsetStr) {
139139
const offset = parseInt(offsetStr, 10);
140-
return Number.isNaN(offset) ? 0 : defaultOffset;
140+
return Number.isNaN(offset) ? defaultOffset : offset;
141141
}
142142
return defaultOffset;
143143
};

0 commit comments

Comments
 (0)