-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
chore: fix form widgets bugs #38492
Merged
+249
−85
Merged
chore: fix form widgets bugs #38492
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3d09e46
fix css selector
jsartisan dee3bf0
add year navigation in calendar
jsartisan d753021
fix styles on calendar
jsartisan 79f2351
add anvil tests in limited
jsartisan 0bb967c
fix input specs
jsartisan 70f2b28
disable snapshot tests
jsartisan c41781c
code review fixes
jsartisan 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 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
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
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,6 +1,7 @@ | ||
# To run only limited tests - give the spec names in below format: | ||
cypress/e2e/Regression/ClientSide/VisualTests/JSEditorIndent_spec.js | ||
#cypress/e2e/Regression/ClientSide/VisualTests/JSEditorIndent_spec.js | ||
# For running all specs - uncomment below: | ||
#cypress/e2e/**/**/* | ||
cypress/e2e/Regression/ClientSide/Anvil/Widgets/* | ||
|
||
#ci-test-limit uses this file to run minimum of specs. Do not run entire suite with this command. |
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
23 changes: 16 additions & 7 deletions
23
app/client/packages/design-system/widgets/src/components/Calendar/src/CalendarHeading.tsx
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
40 changes: 40 additions & 0 deletions
40
...ient/packages/design-system/widgets/src/components/Calendar/src/CalendarMonthDropdown.tsx
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react"; | ||
import type { Key } from "react"; | ||
import { useDateFormatter } from "@react-aria/i18n"; | ||
import { ListBoxItem, Select } from "@appsmith/wds"; | ||
import type { CalendarState } from "@react-stately/calendar"; | ||
|
||
import styles from "./styles.module.css"; | ||
import { useValidMonths } from "../utils/calendar"; | ||
|
||
export function CalendarMonthDropdown({ state }: { state: CalendarState }) { | ||
const formatter = useDateFormatter({ | ||
month: "long", | ||
timeZone: state.timeZone, | ||
}); | ||
|
||
const months = useValidMonths(state, formatter); | ||
|
||
const onChange = (value: Key | null) => { | ||
const date = state.focusedDate.set({ month: Number(value) }); | ||
|
||
state.setFocusedDate(date); | ||
}; | ||
|
||
return ( | ||
<Select | ||
aria-label="Month" | ||
className={styles.monthDropdown} | ||
defaultSelectedKey={state.focusedDate.month} | ||
onSelectionChange={onChange} | ||
placeholder="Select Month" | ||
size="small" | ||
> | ||
{months.map((month, i) => ( | ||
<ListBoxItem id={i} key={i} textValue={month}> | ||
{month} | ||
</ListBoxItem> | ||
))} | ||
</Select> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
...lient/packages/design-system/widgets/src/components/Calendar/src/CalendarYearDropdown.tsx
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import type { Key } from "react"; | ||
import { ListBoxItem, Select } from "@appsmith/wds"; | ||
import type { CalendarState } from "@react-stately/calendar"; | ||
|
||
import { useYearOptions } from "../utils/calendar"; | ||
|
||
export function CalendarYearDropdown({ state }: { state: CalendarState }) { | ||
const years = useYearOptions(state); | ||
|
||
const onChange = (value: Key | null) => { | ||
const index = Number(value); | ||
const date = years[index].value; | ||
|
||
state.setFocusedDate(date); | ||
}; | ||
|
||
return ( | ||
<Select | ||
aria-label="Year" | ||
onSelectionChange={onChange} | ||
placeholder="Select Year" | ||
selectedKey={20} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace hardcoded selectedKey with dynamic value The selectedKey should be calculated based on the current year's position in the years array. - selectedKey={20}
+ selectedKey={years.findIndex(
+ (year) => year.value.compare(state.focusedDate) === 0
+ )}
|
||
size="small" | ||
> | ||
{years.map((year, i) => ( | ||
<ListBoxItem id={i} key={i} textValue={year.formatted}> | ||
{year.formatted} | ||
</ListBoxItem> | ||
))} | ||
</Select> | ||
); | ||
} |
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
52 changes: 52 additions & 0 deletions
52
app/client/packages/design-system/widgets/src/components/Calendar/utils/calendar.ts
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useDateFormatter } from "@react-aria/i18n"; | ||
import type { CalendarState } from "@react-stately/calendar"; | ||
|
||
export function useYearOptions(state: CalendarState) { | ||
const formatter = useDateFormatter({ | ||
year: "numeric", | ||
timeZone: state.timeZone, | ||
}); | ||
|
||
const years: { value: CalendarState["focusedDate"]; formatted: string }[] = | ||
[]; | ||
|
||
const YEAR_RANGE = 20; | ||
|
||
for (let i = -YEAR_RANGE; i <= YEAR_RANGE; i++) { | ||
const date = state.focusedDate.add({ years: i }); | ||
|
||
years.push({ | ||
value: date, | ||
formatted: formatter.format(date.toDate(state.timeZone)), | ||
}); | ||
} | ||
|
||
return years; | ||
} | ||
|
||
export function useValidMonths( | ||
state: CalendarState, | ||
formatter: Intl.DateTimeFormat, | ||
) { | ||
const months = []; | ||
const numMonths = state.focusedDate.calendar.getMonthsInYear( | ||
state.focusedDate, | ||
); | ||
|
||
for (let i = 1; i <= numMonths; i++) { | ||
const date = state.focusedDate.set({ month: i }); | ||
|
||
// Skip months outside valid range | ||
if (state.minValue && date.compare(state.minValue) < 0) { | ||
continue; | ||
} | ||
|
||
if (state.maxValue && date.compare(state.maxValue) > 0) { | ||
continue; | ||
} | ||
|
||
months.push(formatter.format(date.toDate(state.timeZone))); | ||
} | ||
|
||
return months; | ||
} |
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
Oops, something went wrong.
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.
🛠️ Refactor suggestion
Improve selector specificity and accessibility
Two concerns with the current implementation:
input[required]
instead ofinput[aria-required=true]
might affect accessibility.first()
without specific identification could make tests fragileConsider this improvement:
Also, ensure the input has both
required
andaria-required="true"
attributes for better accessibility.📝 Committable suggestion