Skip to content

Commit

Permalink
chore: disabled logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Nov 3, 2023
1 parent febdfaa commit 8449a8d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 7 additions & 1 deletion docs/examples/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ export default () => {
const singleRef = React.useRef<PickerRef>(null);

const [value, setValue] = React.useState<Moment>(null);

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note documentation

Unused variable value.

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note documentation

Unused variable setValue.
const [rangeValue, setRangeValue] = React.useState<[Moment?, Moment?]>([
moment('2000-01-01'),
null,
]);

return (
<div>
{/* <SinglePicker ref={singleRef} suffixIcon="🧶" /> */}
<br />
<RangePicker
{...sharedLocale}
value={[moment('2000-01-01'), null]}
// value={[moment('2000-01-01'), null]}
value={rangeValue}
disabled={[true, false]}
suffixIcon="🧶"
// onFocus={() => {
Expand All @@ -59,6 +64,7 @@ export default () => {
// showTime={{}}
onChange={(val, text) => {
console.log('🔥 Change:', val, text);
setRangeValue(val);
}}
onCalendarChange={(val, text, info) => {
console.log('🎉 Calendar Change:', val, text, info);
Expand Down
5 changes: 4 additions & 1 deletion src/NewPicker/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,10 @@ export default function Picker<DateType = any>(props: RangePickerProps<DateType>
// ======================== Click =========================
const onSelectorClick: React.MouseEventHandler<HTMLDivElement> = () => {
if (focusedIndex === null) {
selectorRef.current.focus(0);
const enabledIndex = mergedDisabled.findIndex((d) => !d);
if (enabledIndex >= 0) {
selectorRef.current.focus(enabledIndex);
}
}

setMergeOpen(true);
Expand Down
8 changes: 5 additions & 3 deletions src/NewPicker/PickerInput/hooks/useRangeValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export default function useRangeValue<DateType = any>(
const mergedOrder = disabled.some((d) => d) ? false : order;

// ============================ Values ============================
const [cachedDefaultValue] = React.useState(defaultValue);

// Used for internal value management.
// It should always use `mergedValue` in render logic
const [internalCalendarValue, setCalendarValue] = React.useState(defaultValue || value);
const [internalCalendarValue, setCalendarValue] = React.useState(cachedDefaultValue || value);
const calendarValue = internalCalendarValue || [null, null];

useLayoutUpdateEffect(() => {
Expand Down Expand Up @@ -133,8 +135,8 @@ export default function useRangeValue<DateType = any>(
(!endEmpty || allowEmpty[1]);

if (validateDateRange) {
// // Sync calendar value with current value
// setCalendarValue(value);
// Sync calendar value with current value
setCalendarValue(cachedDefaultValue || value);

// Sync submit value to not to trigger `onChange` again
setSubmitValue(clone);
Expand Down

0 comments on commit 8449a8d

Please sign in to comment.