Skip to content
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

Pull in the changes made in react-component/picker #6

Closed
wants to merge 4 commits into from
Closed
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
46 changes: 24 additions & 22 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]
on: ['push', 'pull_request']

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- uses: actions/setup-node@v1
- uses: actions/setup-node@v4
with:
node-version: '16'
node-version: '20'

- name: cache package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: create package-lock.json
run: npm i --package-lock-only
run: npm i --package-lock-only --ignore-scripts

- name: hack for singe file
run: |
if [ ! -d "package-temp-dir" ]; then
mkdir package-temp-dir
fi
cp package-lock.json package-temp-dir

- name: cache node_modules
id: node_modules_cache_id
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
Expand All @@ -47,16 +44,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- name: restore cache from package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
Expand All @@ -70,16 +67,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- name: restore cache from package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}
Expand All @@ -93,21 +90,26 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master
uses: actions/checkout@v4

- name: restore cache from package-lock.json
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: package-temp-dir
key: lock-${{ github.sha }}

- name: restore cache from node_modules
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: node_modules-${{ hashFiles('**/package-temp-dir/package-lock.json') }}

- name: coverage
run: npm test -- --coverage && bash <(curl -s https://codecov.io/bash)
run: npm test -- --coverage

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

needs: setup
needs: setup
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-picker",
"version": "4.6.12",
"version": "4.6.13",
"description": "React date & time picker",
"keywords": [
"react",
Expand Down
7 changes: 6 additions & 1 deletion src/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,12 @@ function RangePicker<DateType extends object = any>(

// ======================== Click =========================
const onSelectorClick: React.MouseEventHandler<HTMLDivElement> = (event) => {
if (!selectorRef.current.nativeElement.contains(document.activeElement)) {
const rootNode = (event.target as HTMLElement).getRootNode();
if (
!selectorRef.current.nativeElement.contains(
(rootNode as Document | ShadowRoot).activeElement ?? document.activeElement,
)
) {
// Click to focus the enabled input
const enabledIndex = disabled.findIndex((d) => !d);
if (enabledIndex >= 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/generate/luxon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const normalizeFormatPart = (part: string): string =>
.replace(/D/g, 'd')
.replace(/gg/g, 'kk')
.replace(/Q/g, 'q')
.replace(/([Ww])o/g, 'WW');
.replace(/([Ww])o/g, 'WW')
.replace(/A/g, 'a');

/**
* Normalizes a moment compatible format string to a luxon compatible format string
Expand Down
29 changes: 29 additions & 0 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Note: zombieJ refactoring

import { act, createEvent, fireEvent, render } from '@testing-library/react';
import { createRoot } from 'react-dom/client';
import type { Dayjs } from 'dayjs';
import dayjs from 'dayjs';
import KeyCode from 'rc-util/lib/KeyCode';
Expand Down Expand Up @@ -1973,4 +1974,32 @@ describe('Picker.Range', () => {
]);
expect(isOpen()).toBeFalsy();
});

const renderShadow = (props?: any) => {
const host = document.createElement('div');
document.body.appendChild(host);

const shadowRoot = host.attachShadow({
mode: 'open',
delegatesFocus: false,
});
const container = document.createElement('div');
shadowRoot.appendChild(container);

act(() => {
createRoot(container).render(<DayRangePicker {...props} />);
});

return shadowRoot;
};

it('the end date selector can be selected in shadow dom', () => {
const shadowRoot = renderShadow();

openPicker(shadowRoot, 1);

expect(shadowRoot.querySelectorAll('.rc-picker-input')[1]).toHaveClass(
'rc-picker-input-active',
);
});
});
14 changes: 6 additions & 8 deletions tests/util/commonUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function waitFakeTimer() {
});
}

export function openPicker(container: HTMLElement, index = 0) {
export function openPicker(container: HTMLElement | ShadowRoot, index = 0) {
const input = container.querySelectorAll('input')[index];
fireEvent.mouseDown(input);

Expand All @@ -123,7 +123,7 @@ export function openPicker(container: HTMLElement, index = 0) {
fireEvent.click(input);
}

export function closePicker(container: HTMLElement, index = 0) {
export function closePicker(container: HTMLElement | ShadowRoot, index = 0) {
const input = container.querySelectorAll('input')[index];
fireEvent.blur(input);

Expand Down Expand Up @@ -236,11 +236,9 @@ const dateFnsLocale = {
generateConfig: dateFnsGenerateConfig,
};

type DateFnsSinglePickerProps = Omit<PickerProps<Date>, 'locale' | 'generateConfig'> & React.RefAttributes<PickerRef>;
type DateFnsSinglePickerProps = Omit<PickerProps<Date>, 'locale' | 'generateConfig'> &
React.RefAttributes<PickerRef>;

export const DateFnsSinglePicker = (props: DateFnsSinglePickerProps) => {
return <SinglePicker
{...dateFnsLocale}
{...props}
/>
}
return <SinglePicker {...dateFnsLocale} {...props} />;
};
Loading